Runtime Error for input : {}


  • 0
    W

    I am using bfs to get the rightmost element of every level, and having made the protections against null root It still shows runtime error, Last executed input: {}

    Attached is my code.

     public List<Integer> rightSideView(TreeNode root) {
           if(root==null)
             return (new ArrayList<Integer>());
            List<Integer> ret = new ArrayList<Integer>();
            int levelNum=0;
            Queue<TreeNode> queue[]=new Queue[2];
            queue[0]=new LinkedList<TreeNode>();
            queue[1]=new LinkedList<TreeNode>();
            queue[0].add(root);
            TreeNode n;
            do{
               n=queue[levelNum%2].poll();
               if(n.left!=null) queue[levelNum%2+1].add(n.left);
               if(n.right!=null) queue[levelNum%2+1].add(n.right);
               if(queue[levelNum%2].isEmpty()){
                   ret.add(n.val);
                   levelNum++; 
               }
            }while(queue[levelNum%2].isEmpty());                                    
            return ret;
        }

  • 0
    S

    same here, also tried some of the accepted answers in the discussion board, still runtime error for {},
    i think its a bug here.


  • 0

    This was due to a recent format change to the binary tree representation string. I have just fixed the issue, your could should get Accepted now. Sorry for the inconvenience.


Log in to reply
 

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