A simple 7 line 0ms Java solution


  • 2
    R
    public class Solution {
        public void connect(TreeLinkNode root) {
            if (root == null) { return; }
            for (TreeLinkNode start = root; start.left != null ; start = start.left) {
                for (TreeLinkNode i = start; i != null; i = i.next) {
                    i.left.next = i.right;
                    if (i.next != null) { i.right.next = i.next.left; }
                }
            }
        }
    }
    

  • 0

    66666666666666666666


Log in to reply
 

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