Simple Java 0ms Solution


  • 1
    S

    public class Solution {
    public void connect(TreeLinkNode root) {
    if(root==null){return;}
    root.next=null;
    TreeLinkNode l=root,r=root;
    while(l.left!=null){
    r=l.left;
    while(l.next!=null){
    l.left.next=l.right;l.right.next=l.next.left;l=l.next;
    }
    l.left.next=l.right;l.right.next=null;l=r;
    }
    }
    }


Log in to reply
 

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