일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 잡생각
- 화상영어
- 쓰릴오브파이트
- 10분
- 괜찮음
- 미드시청
- 30분
- English
- 만화도
- 3줄정리
- 뭐든
- 읽기
- 링피트
- 스탭퍼
- 월간
- 파비최
- 매일
- FIT XR
- leetcode
- 프로젝트
- 리얼 클래스
- Problem Solving
- 사이드
- 영어공부
- realclass
- 영어원서읽기
- 개발자
- 운동
- Daily Challenge
- Writing
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/ones-and-zeroes/
Ones and Zeroes - 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
@cache를 쓰는 코드는 처음 봄. 메모이제이션에 사용될 수 있구먼..
처음엔 단순히 0과 1을 세서 m, n보다 작으면 출력하는 문제인 줄 알았는데, 그냥 DP 였음.
class Solution:
def findMaxForm(self, strs: List[str], m: int, n: int) -> int:
counter = [[s.count("0"), s.count("1")] for s in strs]
@cache
def dp(i, j, idx):
if i < 0 or j < 0:
return -math.inf
if idx == len(strs):
return 0
return max(dp(i, j, idx+1), 1 + dp(i-counter[idx][0], j-counter[idx][1], idx+1))
return dp(m, n, 0)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.05.25 |
---|---|
Today's Challenge (0) | 2022.05.24 |
Today's Challenge (0) | 2022.05.22 |
Today's Challenge (0) | 2022.05.21 |
Today's Challenge (0) | 2022.05.20 |
Comments