Skip to content

Commit 85abcb7

Browse files
authored
Merge pull request #607 from daredev127/226-Invert-Binary-Tree
Created 226-Invert-Binary-Tree.cs
2 parents c49a333 + 0d6b097 commit 85abcb7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

csharp/226-Invert-Binary-Tree.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* public int val;
5+
* public TreeNode left;
6+
* public TreeNode right;
7+
* public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
8+
* this.val = val;
9+
* this.left = left;
10+
* this.right = right;
11+
* }
12+
* }
13+
*/
14+
public class Solution
15+
{
16+
public TreeNode InvertTree(TreeNode root)
17+
{
18+
if (root == null) return null;
19+
20+
var tmp = root.left;
21+
root.left = root.right;
22+
root.right = tmp;
23+
24+
InvertTree(root.left);
25+
InvertTree(root.right);
26+
27+
return root;
28+
}
29+
}

0 commit comments

Comments
 (0)