simple Java solution resolve both 116 & 117


  • 0
    C
        LinkedList<TreeLinkNode> q = new LinkedList<>();
        if(root == null) return;
        q.add(root);
        while(!q.isEmpty()) {
            int size = q.size();
            TreeLinkNode prev = new TreeLinkNode(0);
            for(int i=0; i<size; i++) {
                TreeLinkNode node = q.poll();
                prev.next = node;
                prev = node;
                if(node.left != null) q.add(node.left);
                if(node.right != null) q.add(node.right);
            }
        }

Log in to reply
 

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