You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*As long as there is root or stack has length, we loop over. In the loop, if there is a root, we push root into stack and go see the left, until there is no root on left subtree, then we find the nearest last root,and put it into stack, then loop the right subtree.*/varinorderTraversal=function(root){letstack=[];letres=[];while(root||stack.length){if(root){stack.push(root);root=root.left;}else{//find the nearst rootroot=stack.pop();res.push(root.val);root=root.right;}}returnres}
The text was updated successfully, but these errors were encountered:
Given the root of a binary tree, return the inorder traversal of its nodes' values.
Recursive Solution
O(n) iterative solution is awesome!
The text was updated successfully, but these errors were encountered: