Elimination Game LeetCode solution in Java

1
class Solution {
2
public int lastRemaining(int n) {
3
int head = 1;
4
int remain = n;
5
boolean left = true;
6
int step = 1;
7

8
while (remain > 1) {
9
if (left || remain % 2 == 1) {
10
head = head + step;
11
}
12
remain /= 2;
13
step *= 2;
14
left = !left;
15
}
16
return head;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0