Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 537 Bytes

390.md

File metadata and controls

33 lines (24 loc) · 537 Bytes

Elimination Game372 Super Pow

Description

link


Solution

  • See Code

Code

O(n)

class Solution:
    def lastRemaining(self, n: int) -> int:
        left = True
        remaining = n
        step = 1
        head = 1
        while remaining > 1:
            if left or remaining % 2 == 1:
                head = head + step
            remaining = remaining // 2
            step = step * 2
            left = not left
        return head;