일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 쓰릴오브파이트
- 괜찮음
- English
- 10분
- 리얼 클래스
- 읽기
- 영어공부
- Writing
- 뭐든
- 3줄정리
- 미드시청
- 만화도
- 링피트
- leetcode
- 월간
- 화상영어
- realclass
- 사이드
- 개발자
- 파비최
- 영어원서읽기
- 잡생각
- 운동
- 30분
- Problem Solving
- 프로젝트
- FIT XR
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/binary-tree-cameras/
Binary Tree Cameras - 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
Hard 난이도의 문제.
여러 가지로 풀 수 있는데, DP가 제일 쉬워 보여서 선택!
하나.. 소스가 간단해 보였을 뿐.. 이해하기는 꽤 어렵
class Solution:
def minCameraCover(self, root: Optional[TreeNode]) -> int:
def solve(node):
if not node:
return 0, 0, float('inf')
L = solve(node.left)
R = solve(node.right)
dp0 = L[1] + R[1]
dp1 = min(L[2] + min(R[1:]), R[2] + min(L[1:]))
dp2 = 1 + min(L) + min(R)
return dp0, dp1, dp2
return min(solve(root)[1:])
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.06.19 |
---|---|
Today's Challenge (0) | 2022.06.18 |
Today's Challenge (0) | 2022.06.16 |
Today's Challenge (0) | 2022.06.15 |
Today's Challenge (0) | 2022.06.14 |
Comments