Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9c83e09

Browse files
Merge pull request youngyangyang04#2022 from ZerenZhang2022/patch-28
Update 0198.打家劫舍.md
2 parents 5f84ff8 + 801e03a commit 9c83e09

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

‎problems/0198.打家劫舍.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,17 @@ class Solution:
153153
dp[i] = max(dp[i-2]+nums[i], dp[i-1])
154154
return dp[-1]
155155
```
156-
156+
```python
157+
class Solution: # 二维dp数组写法
158+
def rob(self, nums: List[int]) -> int:
159+
dp = [[0,0] for _ in range(len(nums))]
160+
dp[0][1] = nums[0]
161+
for i in range(1,len(nums)):
162+
dp[i][0] = max(dp[i-1][1],dp[i-1][0])
163+
dp[i][1] = dp[i-1][0]+nums[i]
164+
print(dp)
165+
return max(dp[-1])
166+
```
157167
Go:
158168
```Go
159169
func rob(nums []int) int {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /