FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CodingInterviewProblems/LeetCode/JavaScript/invertTree.js at master · vale-c/CodingInterviewProblems · GitHub
vale-c
/
CodingInterviewProblems
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
8
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CodingInterviewProblems
/
LeetCode
/
JavaScript
/
invertTree.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (22 loc) · 577 Bytes
Breadcrumbs
CodingInterviewProblems
/
LeetCode
/
JavaScript
/
invertTree.js
Copy path
File metadata and controls
26 lines (22 loc) · 577 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
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
*
@param
{
TreeNode
} root
*
@return
{
TreeNode
}
*/
var
invertTree
=
function
(
root
)
{
if
(
root
===
null
)
return
null
;
let
tmp
=
root
.
left
;
root
.
left
=
invertTree
(
root
.
right
)
;
root
.
right
=
invertTree
(
tmp
)
;
return
root
;
}
;
/**
* Time Complexity: O(N), where N is the number of nodes in the tree, as each node is visited once.
* Space Complexity: O(H), where H is the height of the tree, due to the recursion stack.
*/
Back
|
FazBrowse Home
|
New Git URL