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 6cafde2

Browse files
Add House Robber
1 parent 1a40ddb commit 6cafde2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Solutions in various programming languages are provided. Enjoy it.
2020
11. [Maximum Product Subarray](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/11-Maximum-Product-Subarray)
2121
12. [Combination Sum III](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/12-Combination-Sum-III)
2222
13. [Insert Interval](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/13-Insert-Interval)
23+
14. [House Robber](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/14-House-Robber)
2324

2425
## August LeetCoding Challenge
2526
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Solution {
2+
public int Rob(int[] nums) {
3+
if(nums.Length == 0) return 0;
4+
5+
var dp = new int[nums.Length+1];
6+
dp[1] = nums[0];
7+
for(int i=1; i<nums.Length; i++){
8+
dp[i+1] = Math.Max(dp[i], dp[i-1] + nums[i]);
9+
}
10+
return dp[nums.Length];
11+
}
12+
}

0 commit comments

Comments
(0)

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