Skip to content

Commit 9b9e519

Browse files
add 3127
1 parent 0adb398 commit 9b9e519

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ _If you like this project, please leave me a star._ ★
99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|----------------------------------------------------------------------
1111
| 3131 |[Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3131.java) | | Easy |
12+
| 3127 |[Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3127.java) | | Easy |
1213
| 3046 |[Split the Array](https://leetcode.com/problems/split-the-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3046.java) | | Easy |
1314
| 3042 |[Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3042.java) | | Easy |
1415
| 3038 |[Maximum Number of Operations With the Same Score I](https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_3038.java) | | Easy |

Diff for: src/main/java/com/fishercoder/solutions/_3127.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _3127 {
4+
public static class Solution1 {
5+
public boolean canMakeSquare(char[][] grid) {
6+
for (int i = 0; i < 2; i++) {
7+
for (int j = 0; j < 2; j++) {
8+
if (isPossible(grid, i, j, 'B') || isPossible(grid, i, j, 'W')) {
9+
return true;
10+
}
11+
}
12+
}
13+
return false;
14+
}
15+
16+
private boolean isPossible(char[][] grid, int startI, int startJ, char color) {
17+
int count = 0;
18+
for (int i = startI; i < startI + 2; i++) {
19+
for (int j = startJ; j < startJ + 2; j++) {
20+
if (grid[i][j] == color) {
21+
count++;
22+
}
23+
}
24+
}
25+
return count >= 3;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)