일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 월간
- 사이드
- 괜찮음
- Daily Challenge
- 미드시청
- 운동
- 30분
- 읽기
- realclass
- 스탭퍼
- Problem Solving
- leetcode
- 영어공부
- 뭐든
- 프로젝트
- 파비최
- Writing
- 영어원서읽기
- 10분
- English
- 개발자
- 매일
- FIT XR
- 3줄정리
- 화상영어
- 쓰릴오브파이트
- 만화도
- 리얼 클래스
- 링피트
- 잡생각
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