Skip to main content
  1. Posts/

LeetCode-2029 石子游戏 IX

·1 min·

LeetCode-2029 石子游戏 IX #

Solution 1 #

分类讨论.

代码如下:

class Solution:
    def stoneGameIX(self, stones: List[int]) -> bool:
        cnt0 = cnt1 = cnt2 = 0
        for val in stones:
            if val % 3 == 0:
                cnt0 += 1
            elif val % 3 == 1:
                cnt1 += 1
            else:
                cnt2 += 1
        if cnt0 % 2 == 0:
            return cnt1 >= 1 and cnt2 >= 1
        return cnt1 - cnt2 > 2 or cnt2 - cnt1 > 2