Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 86554c0

Browse files
committedJan 13, 2020
Add solution #226
1 parent 65c7b11 commit 86554c0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎solutions/0226-invert-binary-tree.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 226. Invert Binary Tree
3+
* https://leetcode.com/problems/invert-binary-tree/
4+
* Difficulty: Easy
5+
*
6+
* Invert a binary tree.
7+
*/
8+
9+
/**
10+
* Definition for a binary tree node.
11+
* function TreeNode(val) {
12+
* this.val = val;
13+
* this.left = this.right = null;
14+
* }
15+
*/
16+
/**
17+
* @param {TreeNode} node
18+
* @return {TreeNode}
19+
*/
20+
var invertTree = function(node) {
21+
if (node) [node.left, node.right] = [invertTree(node.right), invertTree(node.left)];
22+
return node;
23+
};

0 commit comments

Comments
 (0)
Please sign in to comment.