Skip to content

Commit 42f0ff0

Browse files
committed
Create 1991-find-the-middle-index-in-array.rs
1 parent 597d0f8 commit 42f0ff0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub fn find_middle_index(nums: Vec<i32>) -> i32 {
2+
for i in 0..nums.len() {
3+
if nums[0..i].iter().sum::<i32>() == nums[i+1..].iter().sum::<i32>() {
4+
return i as i32;
5+
}
6+
}
7+
-1
8+
}
9+
10+
fn main() {
11+
let nums = vec![1];
12+
println!("{:?}", find_middle_index(nums));
13+
}

0 commit comments

Comments
 (0)