Skip to content

Commit a4869e0

Browse files
authored
house robber solution
1 parent 3561a31 commit a4869e0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

house-robber/yhkee0404.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)