Skip to content

Commit dd4a6a3

Browse files
authored
Update elimination-game.cpp
1 parent 6f9038b commit dd4a6a3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

C++/elimination-game.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
// Time: O(n)
1+
// Time: O(logn)
22
// Space: O(1)
33

44
class Solution {
55
public:
66
int lastRemaining(int n) {
77
int start = 1;
88

9-
for (int i = n, step = 2, direction = 1; i > 1;
10-
i /= 2, step *= 2, direction *= -1) {
9+
for (int step = 2, direction = 1; n > 1;
10+
n /= 2, step *= 2, direction *= -1) {
1111

12-
start += direction * (step * (i / 2) - step / 2);
12+
start += direction * (step * (n / 2) - step / 2);
1313
}
1414

1515
return start;

0 commit comments

Comments
 (0)