Java simple recursive solution easy to understand

  • 0
    public class Solution {
        public void connect(TreeLinkNode root) {
            helper(root, null);
        private void helper(TreeLinkNode root, TreeLinkNode next){
            //Only expand the left node, never the right
            if(root == null) return;
   = next;
            helper(root.left, root.right);
            if(next == null){
                helper(root.right, null);
                helper(root.right, next.left);


Log in to reply

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