This commit is contained in:
Joe Ardent 2024-05-14 16:38:44 -07:00
parent cf517aeac3
commit edbe0571dc

View file

@ -3,7 +3,6 @@ fn main() {
} }
fn f(nums: Vec<i32>) -> i32 { fn f(nums: Vec<i32>) -> i32 {
let mut pivot = -1;
let mut rights = Vec::with_capacity(nums.len()); let mut rights = Vec::with_capacity(nums.len());
let mut cur = 0; let mut cur = 0;
for n in nums.iter().rev() { for n in nums.iter().rev() {
@ -16,9 +15,8 @@ fn f(nums: Vec<i32>) -> i32 {
for (i, num) in nums.into_iter().enumerate() { for (i, num) in nums.into_iter().enumerate() {
cur += num; cur += num;
if cur == rights[i] { if cur == rights[i] {
pivot = i as i32; return i as i32;
break;
} }
} }
pivot -1
} }