My code is like bellow,what should I get runtime error:Last executed input: {}.


  • 0
    Y

    public class Solution {
    public void connect(TreeLinkNode root) {

        if(root == null){
            return;
        }
        
        LinkedList<TreeLinkNode> queue = new LinkedList<TreeLinkNode>();
        
        root.level = 0;
        queue.add(root);
        
        int level = 0;
        TreeLinkNode front = null;
        while(queue.size()>0){
            TreeLinkNode temp = queue.get(0);
            
            if(temp.level != level){
                level++;
                front = null;
            }
            
            temp.next = front;
            front = temp;
            
            if(temp.right != null){
                temp.right.level = level+1;
                queue.add(temp.right);
            }
            
            if(temp.left != null){
                temp.left.level = level+1;
                queue.add(temp.left);
            }
            
            queue.remove(0);
        }
        
    }
    

    }


Log in to reply
 

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