일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 개발자
- 3줄정리
- 프로젝트
- leetcode
- 쓰릴오브파이트
- Problem Solving
- 링피트
- 10분
- 매일
- Daily Challenge
- 리얼 클래스
- 뭐든
- 읽기
- 월간
- 사이드
- realclass
- 미드시청
- Writing
- 영어공부
- 30분
- English
- 파비최
- 영어원서읽기
- 운동
- 스탭퍼
- FIT XR
- 만화도
- 괜찮음
- 화상영어
- 잡생각
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/count-good-nodes-in-binary-tree/
Count Good Nodes in Binary Tree - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
3일 연속 DFS 문제 풀이
class Solution:
def goodNodes(self, root: TreeNode) -> int:
if not root:
return 0
def dfs(node, cur_max):
if not node:
return
if node.val >= cur_max:
count[0] += 1
cur_max = node.val
dfs(node.left, cur_max)
dfs(node.right, cur_max)
count = [0]
dfs(root, root.val)
return count[0]
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.09.03 |
---|---|
Today's Challenge (0) | 2022.09.02 |
Today's Challenge (0) | 2022.08.31 |
Today's Challenge (0) | 2022.08.30 |
Today's Challenge (0) | 2022.08.29 |
Comments