We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3561a31 commit a4869e0Copy full SHA for a4869e0
house-robber/yhkee0404.rs
@@ -0,0 +1,11 @@
1
+impl Solution {
2
+ pub fn rob(nums: Vec<i32>) -> i32 {
3
+ let mut dp = vec![0; nums.len() + 1];
4
+ dp[1] = nums[0];
5
+ for i in 2..dp.len() {
6
+ dp[i] = dp[i - 1].max(dp[i - 2] + nums[i - 1]);
7
+ }
8
+ return *dp.last()
9
+ .unwrap_or(&0)
10
11
+}
0 commit comments