반응형
solution for Invert Binary Tree
Problem)
Invert a binary tree.
Example)
Solution)
class Solution:
def invertTree(self, root: TreeNode) -> TreeNode:
if root:
root.left, root.right = self.invertTree(root.right), self.invertTree(root.left)
return root
else:
return None
Reference)
반응형
'알고리즘 > 코딩 테스트' 카테고리의 다른 글
[Leetcode] Reverse String (0) | 2020.08.19 |
---|---|
[Leetcode] Valid Palindrome (0) | 2020.08.18 |
[Leetcode] Container With Most Water (0) | 2020.06.04 |
[Leetcode] Two City Scheduling (0) | 2020.06.03 |
그래프 탐색 알고리즘 [DFS, BFS] (0) | 2019.02.27 |