It is my Java solution


  • 0
    O
       public static int minDepth(BinaryTree root) {
        	if (root != null) {
    	    		int left = Integer.MAX_VALUE, right = Integer.MAX_VALUE;
    	    		if (root.left != null) {
    	    			left = minDepth(root.left);
    	    		}
    	    		if (root.right != null) {
    	    			right = minDepth(root.right);
    	    		}
    	    		if (left < right) {
    	    			return left + 1;
    	    		} else if (left > right) {
    	    			return right + 1;
    	    		} else if (left == right && left != Integer.MAX_VALUE) {
    	    			return left + 1;
    	    		} else {
    	    			return 1;
    	    		}
        	}  
        	
        	return 0;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.