simply simulate the game itself until you find the victor!
code link to code
class Solution {
public:
bool canAliceWin(int n) {
int toRemove{10};
while(toRemove <= n) {
n -= toRemove--;
}
return toRemove % 2 == 1;
}
};complexity link to complexity
- Time:
O(1)- Space:
O(1)
time taken link to time taken
- 2 minutes and 4 seconds