Kotlin Leetcode - 1025. Divisor Game
題目連接:https://leetcode.com/problems/divisor-game/
class Solution {
fun divisorGame(n: Int): Boolean {
}
}
解題思路
這題題目的說明很複雜
但是有玩過類似遊戲的人可以發現
在兩位玩家用最佳策略的前提下:
- 只要
n
是奇數,Alice 就會輸 - 只要
n
是偶數,Alice 就會贏
Kotlin 參考解答
點擊展開解答
class Solution {
fun divisorGame(n: Int): Boolean {
return n % 2 == 0
}
}
單行表達式的方式如下
class Solution {
fun divisorGame(n: Int) = n % 2 == 0
}
- 回到 leetcode 列表