0 ms JAVA solution


  • 0
    public class Solution {
        public void connect(TreeLinkNode root) {
        	if(root == null || root.left == null) return;
        	TreeLinkNode parent = root;
        	TreeLinkNode left = parent.left;
        	while(left != null){
        		while(parent != null){
        			parent.left.next = parent.right;
        			if(parent.next != null)parent.right.next = parent.next.left;
        			parent = parent.next;
        		}
        		parent = left;
        		left = left.left;
        	}	
        }
    }
    
    

Log in to reply
 

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