2024/08/31 每日一题
LeetCode 3127 构造相同颜色的正方形
方法1:模拟
class Solution {
public boolean canMakeSquare(char[][] grid) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
int cnt = 0; // 统计黑色数量
cnt += grid[i][j] == 'B' ? 1 : 0;
cnt += grid[i + 1][j] == 'B' ? 1 : 0;
cnt += grid[i][j + 1] == 'B' ? 1 : 0;
cnt += grid[i + 1][j + 1] == 'B' ? 1 : 0;
if (cnt >= 3 || cnt <= 1) return true;
}
}
return false;
}
}