Easy java DFS recursive solution with comment

  • 0

    public class Solution {
    public void connect(TreeLinkNode root) {
    if (root == null || root.left == null && root.right == null) return;

        root.left.next = root.right; //bond left node and right node
        if (root.next != null) root.right.next = root.next.left;//bond node between subtrees(only left)


Log in to reply

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