Fix day 3 error case
This doesn't actually matter for the input data given, but it ensures we get the right error when the battery list is too short, instead of unwrapping.
This commit is contained in:
parent
2258f965c1
commit
83e957d5f9
@ -52,6 +52,9 @@ fn max_batteries(n: usize, v: &[u8]) -> Option<Vec<u8>> {
|
|||||||
let mut remaining = n;
|
let mut remaining = n;
|
||||||
let mut slice = v;
|
let mut slice = v;
|
||||||
while remaining > 0 {
|
while remaining > 0 {
|
||||||
|
if slice.len() - remaining + 1 == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let (b, i) = find_max(&slice[..slice.len() - remaining + 1]);
|
let (b, i) = find_max(&slice[..slice.len() - remaining + 1]);
|
||||||
result.push(b);
|
result.push(b);
|
||||||
remaining -= 1;
|
remaining -= 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user