Java O(1) space O(n) time solution


  • 0
    K
    public class Solution {
        public void connect(TreeLinkNode root) {
            TreeLinkNode cur = root;
            while(cur != null && cur.left!=null)
            {
                cur.left.next = cur.right;
                if(cur.next!=null) 
                {
                    cur.right.next = cur.next.left;
                    cur = cur.next;
                }
                else
                {
                    root = root.left;
                    cur = root;
                }
            }
        }
    }

  • 0
    T
    This post is deleted!

Log in to reply
 

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