Skip to content

Commit a43ec4c

Browse files
committed
dp rob houses
1 parent a2dfcc4 commit a43ec4c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/house_robber.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub struct Solution {}
2+
impl Solution {
3+
pub fn robs(nums: Vec<i32>) -> i32 {
4+
let (mut r1, mut r2) = (0, 0);
5+
for num in nums {
6+
let temp = std::cmp::max(num + r1, r2);
7+
r1 = temp;
8+
r2 = num;
9+
}
10+
std::cmp::max(r1, r2)
11+
}
12+
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
mod min_cost_stairs;
1+
mod house_robber;
22
fn main() {}

0 commit comments

Comments
 (0)