我知道是模拟题 我以为会很复杂 结果看了看题解好简单 救命
如果有一天我能读完题就领会其意思 我笔试一定没问题😭😭😭
java:
class Solution {
public boolean winnerOfGame(String colors) {
int n = colors.length();
char[] cs = colors.toCharArray();
int a = 0, b = 0;
for(int i = 1; i < n - 1; i++){
if(cs[i] == 'A' && cs[i - 1] == 'A' && cs[i + 1] == 'A') a++;
if(cs[i] == 'B' && cs[i - 1] == 'B' && cs[i + 1] == 'B') b++;
}
return a > b;
}
}
python3:
class Solution:
def winnerOfGame(self, colors: str) -> bool:
a, b, n = 0, 0, len(colors)
for i in range(1, n - 1):
if colors[i] == 'A' or colors[i - 1] == 'A' or colors[i + 1] == 'A':
a += 1
if colors[i] == 'B' or colors[i - 1] == 'B' or colors[i + 1] == 'B':
b += 1
return a > b