I was trying to convert a binary tree to array and I am confused in it. This is the code I am writing:
var maxDepth = function(root) {
var rc=rc??[];
if(root==null)
return ;
rc.push(root.val);
maxDepth(root.left);
maxDepth(root.right);
return ((rc.length-1)/2)+1;
};
So the problem is that my array always contains 1 element. But according to my understanding , won't after pushing the first element in rc , the nullish coalescing operator will assign the value of rc to the array? Why is it essentially resetting the array?