本文共 539 字,大约阅读时间需要 1 分钟。
class Solution { public: int findTheWinner(int n, int k) { vector dp; for(int i=1;i<=n;++i) dp.push_back(i); auto pos = dp.begin(); while(dp.size()-1) { int count = 1; while(count != k) { pos++; ++count; if(pos == dp.end()) pos = dp.begin(); } pos = dp.erase(pos); if(pos == dp.end()) pos = dp.begin(); } return dp.front(); }};
转载地址:http://vbni.baihongyu.com/