일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 링피트
- 파비최
- 매일
- Problem Solving
- 리얼 클래스
- 10분
- 쓰릴오브파이트
- 영어공부
- 미드시청
- Daily Challenge
- English
- 개발자
- 스탭퍼
- 3줄정리
- realclass
- FIT XR
- 영어원서읽기
- 읽기
- 뭐든
- 사이드
- Writing
- 괜찮음
- 잡생각
- 만화도
- leetcode
- 화상영어
- 프로젝트
- 월간
- 운동
- 30분
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.18 Today's Challenge 본문
https://leetcode.com/problems/invert-binary-tree/
Invert Binary Tree - LeetCode
Invert Binary Tree - Given the root of a binary tree, invert the tree, and return its root. Example 1: [https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg] Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: [https://assets.lee
leetcode.com
재귀로 앞뒤 바꾸는 로직 호출하면 됨.
class Solution:
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
if not root:
return root
self.invertTree(root.left)
self.invertTree(root.right)
root.left, root.right = root.right, root.left
return root
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.02.20 Today's Challenge (0) | 2023.02.20 |
---|---|
2023.02.19 Today's Challenge (0) | 2023.02.19 |
2023.02.17 Today's Challenge (0) | 2023.02.17 |
2023.02.16 Today's Challenge (1) | 2023.02.16 |
2023.02.15 Today's Challenge (0) | 2023.02.15 |
Comments