| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 프로젝트
- 파비최
- 매일
- English
- 영어원서읽기
- 30분
- 쓰릴오브파이트
- 운동
- leetcode
- Problem Solving
- 스탭퍼
- Daily Challenge
- 링피트
- 영어공부
- 뭐든
- 미드시청
- 화상영어
- 월간
- realclass
- FIT XR
- 3줄정리
- 괜찮음
- 만화도
- Writing
- 10분
- 리얼 클래스
- 사이드
- 읽기
- 잡생각
- 개발자
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/same-tree/
Same Tree - LeetCode
Same Tree - Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. Example 1: [https://assets.le
leetcode.com
복잡하게 트리 순회를 쭉 했는데 계속 테스트 케이스에서 틀려서 솔루션 참고.
재귀로 풀면 간단히 풀림.
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
if not p and not q:
return True
if p and q and p.val == q.val:
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
else:
return False반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| Today's Challenge (0) | 2023.01.12 |
|---|---|
| Today's Challenge (0) | 2023.01.11 |
| Today's Challenge (0) | 2023.01.09 |
| Today's Challenge (0) | 2023.01.08 |
| Today's Challenge (0) | 2023.01.07 |
Comments