Why it is timeout error


  • 1
    J

    Hi all,

    I used level-order traversal to solve this problem and maintain two queues for the current level and next level, but the problem is that the system shows "timeout" error when I submit it. My code is doing fine in my test data, can you help me figure out what caused this "timeout" error? Thanks

    public class Solution {
        public int minDepth(TreeNode root) {
            int minDepth = 0;
            if (root == null)
                return 0;
    
            ArrayList<TreeNode> currLevel = new ArrayList<TreeNode>();
            ArrayList<TreeNode> nextLevel = new ArrayList<TreeNode>();
            currLevel.add(root);
    
            while(!currLevel.isEmpty()) {
                TreeNode tn = currLevel.get(0);
                currLevel.remove(0);
    
                if(tn != null) {
                    if(tn.left == null && tn.right == null)
                        return ++minDepth;
                    nextLevel.add(tn.left);
                    nextLevel.add(tn.right);
                }
    
                if(currLevel.isEmpty()) {
                    minDepth++;
                    currLevel = (ArrayList)nextLevel.clone();
                    nextLevel.clear();
                }
            }
            return minDepth;   
        }
    }

  • 9
    S

    Time out is server's problem, please try submit again.

    Sorry for this inconvenience.


  • 0
    J

    Thanks. I resubmitted it without any change, and it is accepted this time.


Log in to reply
 

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