3127. Make a Square with the Same Color Easy
1/**
2 * [3127] Make a Square with the Same Color
3 *
4 * You are given a 2D matrix grid of size 3 x 3 consisting only of characters 'B' and 'W'. Character 'W' represents the white color<!-- notionvc: 06a49cc0-a296-4bd2-9bfe-c8818edeb53a -->, and character 'B' represents the black color<!-- notionvc: 06a49cc0-a296-4bd2-9bfe-c8818edeb53a -->.
5 * Your task is to change the color of at most one cell<!-- notionvc: c04cb478-8dd5-49b1-80bb-727c6b1e0232 --> so that the matrix has a 2 x 2 square where all cells are of the same color.<!-- notionvc: adf957e1-fa0f-40e5-9a2e-933b95e276a7 -->
6 * Return true if it is possible to create a 2 x 2 square of the same color, otherwise, return false.
7 *
8 * <style type="text/css">.grid-container {
9 * display: grid;
10 * grid-template-columns: 30px 30px 30px;
11 * padding: 10px;
12 * }
13 * .grid-item {
14 * background-color: black;
15 * border: 1px solid gray;
16 * height: 30px;
17 * font-size: 30px;
18 * text-align: center;
19 * }
20 * .grid-item-white {
21 * background-color: white;
22 * }
23 * </style>
24 * <style class="darkreader darkreader--sync" media="screen" type="text/css">
25 * </style>
26 * <strong class="example">Example 1:
27 * <div class="grid-container">
28 * <div class="grid-item"> </div>
29 * <div class="grid-item grid-item-white"> </div>
30 * <div class="grid-item"> </div>
31 * <div class="grid-item"> </div>
32 * <div class="grid-item grid-item-white"> </div>
33 * <div class="grid-item grid-item-white"> </div>
34 * <div class="grid-item"> </div>
35 * <div class="grid-item grid-item-white"> </div>
36 * <div class="grid-item"> </div>
37 * </div>
38 * <div class="example-block">
39 * Input: <span class="example-io">grid = [["B","W","B"],["B","W","W"],["B","W","B"]]</span>
40 * Output: <span class="example-io">true</span>
41 * Explanation:
42 * It can be done by changing the color of the grid[0][2].
43 * </div>
44 * <strong class="example">Example 2:
45 * <div class="grid-container">
46 * <div class="grid-item"> </div>
47 * <div class="grid-item grid-item-white"> </div>
48 * <div class="grid-item"> </div>
49 * <div class="grid-item grid-item-white"> </div>
50 * <div class="grid-item"> </div>
51 * <div class="grid-item grid-item-white"> </div>
52 * <div class="grid-item"> </div>
53 * <div class="grid-item grid-item-white"> </div>
54 * <div class="grid-item"> </div>
55 * </div>
56 * <div class="example-block">
57 * Input: <span class="example-io">grid = [["B","W","B"],["W","B","W"],["B","W","B"]]</span>
58 * Output: <span class="example-io">false</span>
59 * Explanation:
60 * It cannot be done by changing at most one cell.
61 * </div>
62 * <strong class="example">Example 3:
63 * <div class="grid-container">
64 * <div class="grid-item"> </div>
65 * <div class="grid-item grid-item-white"> </div>
66 * <div class="grid-item"> </div>
67 * <div class="grid-item"> </div>
68 * <div class="grid-item grid-item-white"> </div>
69 * <div class="grid-item grid-item-white"> </div>
70 * <div class="grid-item"> </div>
71 * <div class="grid-item grid-item-white"> </div>
72 * <div class="grid-item grid-item-white"> </div>
73 * </div>
74 * <div class="example-block">
75 * Input: <span class="example-io">grid = [["B","W","B"],["B","W","W"],["B","W","W"]]</span>
76 * Output: <span class="example-io">true</span>
77 * Explanation:
78 * The grid already contains a 2 x 2 square of the same color.<!-- notionvc: 9a8b2d3d-1e73-457a-abe0-c16af51ad5c2 -->
79 * </div>
80 *
81 * Constraints:
82 *
83 * grid.length == 3
84 * grid[i].length == 3
85 * grid[i][j] is either 'W' or 'B'.
86 *
87 */
88pub struct Solution {}
89
90// problem: https://leetcode.com/problems/make-a-square-with-the-same-color/
91// discuss: https://leetcode.com/problems/make-a-square-with-the-same-color/discuss/?currentPage=1&orderBy=most_votes&query=
92
93// submission codes start here
94
95impl Solution {
96 pub fn can_make_square(grid: Vec<Vec<char>>) -> bool {
97 false
98 }
99}
100
101// submission codes end
102
103#[cfg(test)]
104mod tests {
105 use super::*;
106
107 #[test]
108 fn test_3127() {
109 }
110}
111
Back
© 2025 bowen.ge All Rights Reserved.