Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85abcb7

Browse files
authored
Merge pull requestneetcode-gh#607 from daredev127/226-Invert-Binary-Tree
Created 226-Invert-Binary-Tree.cs
2 parentsc49a333 +0d6b097 commit85abcb7

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+
publicclassSolution
15+
{
16+
publicTreeNodeInvertTree(TreeNoderoot)
17+
{
18+
if(root==null)returnnull;
19+
20+
vartmp=root.left;
21+
root.left=root.right;
22+
root.right=tmp;
23+
24+
InvertTree(root.left);
25+
InvertTree(root.right);
26+
27+
returnroot;
28+
}
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp