The results of run code and submit are inconsistent


  • 0
    S

    When i submit
    Input: [1,2]
    Output: 1.
    Corret: 2

    When i 'try code'
    Input: [1,2]
    Output: 2.
    Correct 2

    Is it leetcode with a bug? I dont see others having similar issue on this discussion board. This is the 2nd question in a row with an issue like this. The other one is:
    https://leetcode.com/problems/balanced-binary-tree/description/
    Same thing there. try code's output is correct but when i submit it fails.

    Here is my code:

    class Solution {
      private static int min = (int) Integer.MAX_VALUE;
    
      public int minDepth(TreeNode root) {
        if(root == null){
          return 0;
        }
    
        depth(root, 1);
        return min;
      }
    
      public static int depth(TreeNode root, int dep){
        if(root == null){
          return dep;
        }
    
        if(root.left == null && root.right == null)
          min = Math.min(min, dep);
    
        return Math.max(dep, Math.max( depth(root.left, dep+1), depth(root.right, dep+1) ) );
      }
    }
    

Log in to reply
 

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