3782. Last Remaining Integer After Alternating Deletion Operations
You are given an integer
n.We write the integers from 1 to
nin a sequence from left to right. Then, alternately apply the following two operations until only one integer remains, starting with operation 1:
- Operation 1: Starting from the left, delete every second number.
- Operation 2: Starting from the right, delete every second number.
Return the last remaining integer.
1 | class Solution { |