일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- kaggle
- 파이썬
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 프로그래머스
- Protocol
- shiba
- 밴픽
- DWG
- 109. Convert Sorted List to Binary Search Tree
- data science
- Generator
- Class
- 컴퓨터의 구조
- LeetCode
- attribute
- 30. Substring with Concatenation of All Words
- Python Code
- Python
- Python Implementation
- Decorator
- 43. Multiply Strings
- iterator
- Substring with Concatenation of All Words
- 운영체제
- Regular Expression
- t1
- concurrency
- 시바견
- 715. Range Module
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 |