일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Class
- Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- Substring with Concatenation of All Words
- iterator
- Python Implementation
- 밴픽
- Regular Expression
- data science
- 109. Convert Sorted List to Binary Search Tree
- attribute
- Decorator
- concurrency
- 파이썬
- Python Code
- shiba
- 프로그래머스
- 715. Range Module
- 시바견
- Protocol
- 컴퓨터의 구조
- 운영체제
- t1
- LeetCode
- Generator
- Python
- DWG
- 315. Count of Smaller Numbers After Self
- 30. Substring with Concatenation of All Words
- kaggle
Archives
- Today
- Total
Scribbling
LeetCode: 198. House Robber 본문
DP 기초 문제로 맨날 보는 문제
class Solution:
def rob(self, nums: List[int]) -> int:
if len(nums) <= 2:
return max(nums)
dp = [0] * len(nums)
dp[0] = nums[0]
dp[1] = max(nums[0], nums[1])
for i in range(2, len(nums)):
dp[i] = max(dp[i-2]+nums[i], dp[i-1])
return dp[len(nums)-1]
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 1011. Capacity To Ship Packages Within D Days (0) | 2021.12.06 |
---|---|
LeetCode: 204. Count Primes (0) | 2021.12.05 |
LeetCode: 179. Largest Number (0) | 2021.12.04 |
LeetCode: 172. Factorial Trailing Zeroes (0) | 2021.12.04 |
LeetCode: 160. Intersection of Two Linked Lists (0) | 2021.12.02 |