Coding Test Practice/Python
[LeetCode - Easy] 1025. Divisor Game
y2r1m
2023. 5. 1. 21:24
https://leetcode.com/problems/divisor-game/
Divisor Game - LeetCode
Can you solve this real interview question? Divisor Game - Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of: * Choosing any x
leetcode.com
게임을 이해하여 n이 짝수이면 무조건 Alice가, 홀수이면 Bob이 이긴다는 규칙을 찾아내 간단히 해결 가능
class Solution:
def divisorGame(self, n: int) -> bool:
if n % 2 == 0: # 둘 다 최적으로 움직이기 때문에, 짝수이면 Alice가 이기고 홀수이면 Bob이 이기는 규칙 존재
return True
else:
return False