Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion problems/198.house-robber.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ return b;

## 代码

* 语言支持:JS, C++
* 语言支持:JS,C++,Python

JavaScript Code:

Expand Down Expand Up @@ -142,8 +142,11 @@ var rob = function(nums) {
return dp[nums.length + 1];
};
```

C++ Code:

> 与JavaScript代码略有差异,但状态迁移方程是一样的。

```C++
class Solution {
public:
Expand All @@ -162,3 +165,22 @@ public:
}
};
```

Python Code:

```python
class Solution:
def rob(self, nums: List[int]) -> int:
if not nums:
return 0

length = len(nums)
if length == 1:
return nums[0]
else:
prev = nums[0]
cur = max(prev, nums[1])
for i in range(2, length):
cur, prev = max(prev + nums[i], cur), cur
return cur
```