public class Solution extends Object
390 - Elimination Game.
Medium
You have a list arr
of all integers in the range [1, n]
sorted in a strictly increasing order. Apply the following algorithm on arr
:
Given the integer n
, return the last number that remains in arr
.
Example 1:
Input: n = 9
Output: 6
Explanation:
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr = [2, 4, 6, 8]
arr = [2, 6]
arr = [6]
Example 2:
Input: n = 1
Output: 1
Constraints:
1 <= n <= 109
Constructor and Description |
---|
Solution() |
Modifier and Type | Method and Description |
---|---|
int |
lastRemaining(int n) |
Copyright © 2022. All rights reserved.