Skip to content

Commit

Permalink
61: Re-submit
Browse files Browse the repository at this point in the history
  • Loading branch information
sankichi92 committed Dec 30, 2023
1 parent b8c467a commit ed5f462
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 61-house-robber/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
pub fn rob(nums: Vec<i32>) -> i32 {
if nums.len() == 1 {
return nums[0];
}

if nums.len() == 2 {
return nums[0].max(nums[1]);
}

let (mut cand1, mut cand2, mut prev) = (nums[0], nums[1], nums[0] + nums[2]);

for num in nums.iter().skip(3) {
Expand All @@ -21,4 +29,9 @@ mod tests {
fn case2() {
assert_eq!(rob(vec![2, 7, 9, 3, 1]), 12);
}

#[test]
fn failed_case1() {
assert_eq!(rob(vec![0]), 0);
}
}

0 comments on commit ed5f462

Please sign in to comment.