3398. Make a Square with the Same Color
My accepted Python solution to LeetCode problem 3398, Make a Square with the Same Color, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2026-01-01.
class Solution:
def canMakeSquare(self, grid: List[List[str]]) -> bool:
# Check all 2x2 squares
for i in range(2):
for j in range(2):
cells = [grid[i][j], grid[i][j+1], grid[i+1][j], grid[i+1][j+1]]
black = cells.count('B')
white = cells.count('W')
# If at least 3 same color, can make all same
if black >= 3 or white >= 3:
return True
return False