My Simple recursive Java solution with just two "if"


  • 0
    X

    '''
    public void connect(TreeLinkNode root) {
    if(root == null) {
    return;
    }
    if(root.left != null && root.right != null) {
    root.left.next = root.right;
    root.right.next = root.next == null ? null : root.next.left;
    }
    connect(root.left);
    connect(root.right);
    }
    '''


Log in to reply
 

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