GuilinDev

Lc1823

05 August 2008

1823 Find the Winner of the Circular Game

每轮踢出当前序号开始的第k个人,最后剩下的就是获胜者

1
2
3
4
5
6
7
8
9
class Solution {
    public int findTheWinner(int n, int k) {
        int dp = 1;
        for(int i = 0 ; i < n ; i++){
            dp = (dp + k - 1) % (i+1) + 1;
        }
        return dp;
    }
}

动态规划