Flip binary tree js

Flip a binary tree.

Example:

Input:

     4
   /   \
  2     7
 / \   / \
1   3 6   9

Output:

     4
   /   \
  7     2
 / \   / \
9   6 3   1

 1 var invertTree = function (root) {
 2   if (root !== null) {
 3     var temp = root.left;
 4     root.left = root.right;
 5     root.right = temp;
 6     invertTree(root.left);
 7     invertTree(root.right);
 8   }
 9   return root;
10 
11 }

Guess you like

Origin www.cnblogs.com/ajaxkong/p/12041745.html