2029. Stone Game IX
/**
* Problem: LeetCode 2029 - Stone Game IX
* Difficulty: Medium
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public boolean stoneGameIX(int[] stones) {
int[] cnt = new int[3];
for (int s : stones) {
cnt[s % 3]++;
}
if (cnt[0] % 2 == 0) {
return cnt[1] >= 1 && cnt[2] >= 1;
} else {
return Math.abs(cnt[1] - cnt[2]) > 2;
}
}
}
"""
Problem: LeetCode 2029 - Stone Game IX
Difficulty: Medium
Language: Python
Author: CodeByTushu
"""
from typing import List
class Solution:
def stoneGameIX(self, stones: List[int]) -> bool:
cnt = [0] * 3
for s in stones:
cnt[s % 3] += 1
if cnt[0] % 2 == 0:
return cnt[1] >= 1 and cnt[2] >= 1
else:
return abs(cnt[1] - cnt[2]) > 2
/**
* Problem: LeetCode 2029 - Stone Game IX
* Difficulty: Medium
* Language: C++
* Author: CodeByTushu
*/
#include <vector>
#include <cmath>
#include <cstdlib>
using namespace std;
/**
* Problem: LeetCode 2029 - Stone Game IX
* Difficulty: Medium
* Language: C++
* Author: CodeByTushu
*/
class Solution {
public:
bool stoneGameIX(vector<int>& stones) {
int cnt[3] = {0, 0, 0};
for (int s : stones) {
cnt[s % 3]++;
}
if (cnt[0] % 2 == 0) {
return cnt[1] >= 1 && cnt[2] >= 1;
} else {
return abs(cnt[1] - cnt[2]) > 2;
}
}
};
/**
* Problem: LeetCode 2029 - Stone Game IX
* Difficulty: Medium
* Language: JavaScript
* Author: CodeByTushu
*/
var stoneGameIX = function(stones) {
const cnt = [0, 0, 0];
for (const s of stones) {
cnt[s % 3]++;
}
if (cnt[0] % 2 === 0) {
return cnt[1] >= 1 && cnt[2] >= 1;
} else {
return Math.abs(cnt[1] - cnt[2]) > 2;
}
};