213.打家劫舍 II 函数式解法
This commit is contained in:
parent
8fe6cad67b
commit
d401a3d9ef
|
@ -32,6 +32,9 @@ impl Solution {
|
|||
///
|
||||
/// 👍 529 👎 0
|
||||
pub fn rob2(nums: Vec<i32>) -> i32 {
|
||||
nums[0..(nums.len() - 1)].iter().fold((0, 0), |(a, b), &x| (b, b.max(a + x))).1.max(nums[1..nums.len()].iter().fold((0, 0), |(a, b), &x| (b, b.max(a + x))).1).max(nums[0])
|
||||
}
|
||||
/*pub fn rob2(nums: Vec<i32>) -> i32 {
|
||||
let length = nums.len();
|
||||
if length == 1 {
|
||||
return nums[0];
|
||||
|
@ -48,7 +51,7 @@ impl Solution {
|
|||
second
|
||||
};
|
||||
return rob_range(&nums, 0, length - 2).max(rob_range(&nums, 1, length - 1));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue