트리를 좌우대칭으로 바꾼다.
heap정렬을 하면서, 각 층에서 node들을 stack에 넣고 꺼낸다.
재귀
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {TreeNode}
*/
// 1. root가 없으면 return null;
// 2. create temp cariable and assign to root.left.
// 3. change root.left to equql root.right
// 4. change root.right to qqual ro temp
// 5. InverTree(root.left)
// 6. InverTree(root.right)
// Time Complexity: O(n)
// Space Complexity: O(n)
var invertTree = function(root) {
if (!root) return null;
let temp = root.left;
root.left = root.right;
root.right = temp;
invertTree(root.left);
invertTree(root.right);
return root;
};