일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 링피트
- 만화도
- 화상영어
- 파비최
- 10분
- 잡생각
- leetcode
- realclass
- 읽기
- 스탭퍼
- 운동
- 개발자
- 영어공부
- 3줄정리
- Problem Solving
- 쓰릴오브파이트
- 사이드
- Daily Challenge
- 30분
- 뭐든
- 매일
- 프로젝트
- 리얼 클래스
- Writing
- English
- 월간
- 영어원서읽기
- FIT XR
- 미드시청
- 괜찮음
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.13 Today's Challenge 본문
https://leetcode.com/problems/symmetric-tree/
Symmetric Tree - LeetCode
Can you solve this real interview question? Symmetric Tree - Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1: [https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg] Input: roo
leetcode.com
class Solution:
def isMirror(self, left, right):
if not left and not right:
return True
if not left or not right:
return False
return left.val == right.val and self.isMirror(left.left, right.right) and self.isMirror(left.right, right.left)
def isSymmetric(self, root: Optional[TreeNode]) -> bool:
if not root:
return True
return self.isMirror(root.left, root.right)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.15 Today's Challenge (0) | 2023.03.15 |
---|---|
2023.03.14 Today's Challenge (0) | 2023.03.14 |
2023.03.12 Today's Challenge (0) | 2023.03.12 |
2023.03.11 Today's Challenge (0) | 2023.03.11 |
2023.03.10 Today's Challenge (0) | 2023.03.10 |
Comments