Class Solution
-
- All Implemented Interfaces:
public final class Solution3127 - Make a Square with the Same Color\.
Easy
You are given a 2D matrix
gridof size3 x 3consisting only of characters'B'and'W'. Character'W'represents the white color, and character'B'represents the black color.Your task is to change the color of at most one cell so that the matrix has a
2 x 2square where all cells are of the same color.Return
trueif it is possible to create a2 x 2square of the same color, otherwise, returnfalse.Example 1:
Input: grid = \[\["B","W","B"],"B","W","W","B","W","B"]
Output: true
Explanation:
It can be done by changing the color of the
grid[0][2].Example 2:
Input: grid = \[\["B","W","B"],"W","B","W","B","W","B"]
Output: false
Explanation:
It cannot be done by changing at most one cell.
Example 3:
Input: grid = \[\["B","W","B"],"B","W","W","B","W","W"]
Output: true
Explanation:
The
gridalready contains a2 x 2square of the same color.Constraints:
grid.length == 3grid[i].length == 3grid[i][j]is either'W'or'B'.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleancanMakeSquare(Array<CharArray> grid)-
-
Method Detail
-
canMakeSquare
final Boolean canMakeSquare(Array<CharArray> grid)
-
-
-
-