1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public boolean canMakeSquare(char[][] grid) {
for (int i = 0; i < grid.length - 1; i++) { for (int j = 0; j < grid[i].length - 1; j++) { int whiteCount = whiteCount(grid[i][j]) + whiteCount(grid[i][j + 1]) + whiteCount(grid[i + 1][j]) + whiteCount(grid[i + 1][j + 1]); if (whiteCount != 2) { return true; } } }
return false; }
private int whiteCount(char c) { return c == 'W' ? 1 : 0; } }
|
Reference
3127. Make a Square with the Same Color