We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4c8f680 commit cd72027Copy full SHA for cd72027
1 file changed
DSA/DFS/InvertBinaryTree.js
@@ -0,0 +1,16 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
+
10
+var invertTree = function(root) {
11
+ if(!root) {
12
+ return null;
13
+ }
14
+ [root.left, root.right] = [invertTree(root.right), invertTree(root.left)];
15
+ return root;
16
+};
0 commit comments