Skip to content

Commit 6140e6c

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 2.10 MB (Top 66.67%)
1 parent 8e89e76 commit 6140e6c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Runtime: 0 ms (Top 100.0%) | Memory: 2.10 MB (Top 66.67%)
2+
3+
impl Solution {
4+
pub fn last_remaining(n: i32) -> i32 {
5+
let mut n = n;
6+
let mut head = 1;
7+
let mut step = 1;
8+
let mut left = true;
9+
while n > 1 {
10+
if left || n % 2 == 1 {
11+
head += step;
12+
}
13+
n /= 2;
14+
step *= 2;
15+
left = !left;
16+
}
17+
head
18+
}
19+
}

0 commit comments

Comments
 (0)