g0301_0400.s0390_elimination_game.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g0301_0400.s0390_elimination_game;
// #Medium #Math
public class Solution {
public int lastRemaining(int n) {
return n == 1 ? 1 : 2 * (n / 2 - lastRemaining(n / 2) + 1);
}
}