Skip to content

Commit 6231777

Browse files
committed
solve 1
1 parent 4246af3 commit 6231777

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

invert-binary-tree/pmjuu.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
시간복잡도: O(n)
3+
공간복잡도: O(n)
4+
'''
5+
from typing import Optional
6+
7+
8+
class TreeNode:
9+
def __init__(self, val=0, left=None, right=None):
10+
self.val = val
11+
self.left = left
12+
self.right = right
13+
14+
class Solution:
15+
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
16+
if not root:
17+
return None
18+
19+
root.left, root.right = self.invertTree(root.right), self.invertTree(root.left)
20+
21+
return root

0 commit comments

Comments
 (0)