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