프로그래밍/LeetCode
C++ 1025. Divisor Game(Leet Code)
devsu
2020. 6. 13. 18:56
Leet Code_1025. Divisor Game
Dynamic Programming
https://leetcode.com/problems/divisor-game/

문제 해석
이 문제를 풀기위해 이해해야 할 내용은 다음과 같습니다.
목표
Alice가 이기면 true, Bob이 이기면 false
방법
1. 나누어 떨어지면 그수만큼 뺀다
결과
Alice가 이기면 true, Bob이 이기면 false
통과한 코드
class Solution {
public:
bool divisorGame(int N) {
int x = 1;
int nCount = 0;
while(N > 1)
{
if(N % x == 0)
{
nCount++;
N -= x;
}
}
if(nCount % 2 == 1)
return true;
else
return false;
}
};