Why isn't my solution working?


  • 0
    W
    var connect = function(root) {
        if (root !== null) {
    	//making all the right edge nodes point to null
    	var current = root;
    	while(current) {
    		current.next = null;
    		current = current.right;
    	}
    	
    	//ensure there's a second level to the tree
    	if (root.left) {
    		subConnect(root);
    	}
      }
    };
    
    function subConnect(node) {
    node.left.next = node.right;
    if (node.left.left) {
    	subConnect(node.left);
    	subConnect(node.right);
       }
    }
    
     Output: {0,#,1,2,#,3,4,#,6,#}
    Expected: {0,#,1,2,#,3,4,5,6,#}
    

    Not particularly sure what's going on here.


Log in to reply
 

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