Skip to content

Commit 2b8dd26

Browse files
authored
Create Solution2.rs
1 parent 1b4cde1 commit 2b8dd26

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
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 n = nums.len();
4+
let mut f = vec![0; n + 1];
5+
f[1] = nums[0];
6+
for i in 2..=n {
7+
f[i] = f[i - 1].max(f[i - 2] + nums[i - 1]);
8+
}
9+
f[n]
10+
}
11+
}

0 commit comments

Comments
 (0)