跳至主要内容

3222. Find the Winning Player in Coin Game

class Solution {
public:
string losingPlayer(int x, int y)
{
int cnt = 0;
while (x > 0 && y > 3)
{
x -= 1;
y -= 4;
++cnt;
}
return cnt % 2 == 1 ? "Alice" : "Bob";
}
};
  • T: O(n)O(n)
  • S: O(1)O(1)