Elimination Game LeetCode solution in Rust

1
impl Solution {
2
pub fn last_remaining(n: i32) -> i32 {
3
let mut n = n;
4
let mut head = 1;
5
let mut step = 1;
6
let mut left = true;
7
while n > 1 {
8
if left || n % 2 == 1 {
9
head += step;
10
}
11
n /= 2;
12
step *= 2;
13
left = !left;
14
}
15
head
16
}
17
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0