Share my LOOP JAVA 1MS solution!! Easy understand!!


  • 9
    H
    //Just remember to use result from the last step
    public class Solution {
        public void connect(TreeLinkNode root) {
            if(root==null) return;
            while(root.left!=null){
                TreeLinkNode tmp = root;
                while(tmp!=null){
                    tmp.left.next = tmp.right;
                    if(tmp.next!=null) tmp.right.next = tmp.next.left;
                    tmp = tmp.next;
                }
                root = root.left;
            }
        }
    }

Log in to reply
 

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