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