FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/LeetCode/LeetCode226.java at master · git-jhy/JavaArithmetic · GitHub
git-jhy
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode226.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (26 loc) · 757 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode226.java
Copy path
File metadata and controls
35 lines (26 loc) · 757 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package
LeetCode
;
public
class
LeetCode226
{
/// 226. Invert Binary Tree
/// https://leetcode.com/problems/invert-binary-tree/description/
/// 时间复杂度: O(n), n为树中节点个数
/// 空间复杂度: O(h), h为树的高度
public
class
TreeNode
{
int
val
;
TreeNode
left
;
TreeNode
right
;
TreeNode
(
int
x
) {
val
=
x
;
}
}
public
TreeNode
invertTree
(
TreeNode
root
) {
if
(
root
==
null
)
return
null
;
// 左边翻转,右边翻转
TreeNode
left
=
invertTree
(
root
.
left
);
TreeNode
right
=
invertTree
(
root
.
right
);
// 左右交换!
root
.
left
=
right
;
root
.
right
=
left
;
return
root
;
}
}
Back
|
FazBrowse Home
|
New Git URL