Skip to content

Commit 212c7fb

Browse files
committed
Create 2293-min-max-game.rs
1 parent 1eb0c23 commit 212c7fb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2293-min-max-game.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pub fn min_max_game(nums: Vec<i32>) -> i32 {
2+
let mut nums = nums.clone();
3+
while nums.len() > 1 {
4+
let nums_chunks = nums.chunks(2);
5+
let mut tmp = vec!();
6+
for (i, chunk) in nums_chunks.enumerate() {
7+
if i % 2 == 0 {
8+
tmp.push(*chunk.iter().min().unwrap());
9+
} else {
10+
tmp.push(*chunk.iter().max().unwrap());
11+
}
12+
}
13+
nums = tmp;
14+
}
15+
nums[0]
16+
}
17+
18+
fn main() {
19+
let nums = vec![1,3,5,2,4,8,2,2];
20+
println!("{:?}", min_max_game(nums));
21+
}

0 commit comments

Comments
 (0)