question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
make-a-square-with-the-same-color
Beats 100% | Python | Easy to Understand | Complex to Write 🌚🕺🦹‍♂️
beats-100-python-easy-to-understand-comp-22pv
IntuitionFOR THE LACKWITS!!! There are only 9 cells. Square is made up of 4 cells. There are only 4 squares. So, why not hard code it?!!ApproachComplexity Time
aman-sagar
NORMAL
2025-01-27T17:29:34.781555+00:00
2025-01-27T17:29:34.781555+00:00
40
false
# Intuition **FOR THE LACKWITS!!!** There are only 9 cells. Square is made up of 4 cells. There are only 4 squares. So, why not hard code it?!! # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(1) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complex...
1
0
['Array', 'Matrix', 'Enumeration', 'Python3']
1
make-a-square-with-the-same-color
0ms 100% beat in java very easiest code 😊.
0ms-100-beat-in-java-very-easiest-code-b-delo
Code
Galani_jenis
NORMAL
2025-01-08T11:43:54.375573+00:00
2025-01-08T11:43:54.375573+00:00
114
false
![94da60ee-7268-414c-b977-2403d3530840_1725903127.9303432.png](https://assets.leetcode.com/users/images/7a567181-0007-4cec-aebc-82d3126d9742_1736336518.5675416.png) # Code ```java [] class Solution { public boolean canMakeSquare(char[][] grid) { byte countB = 0, countW = 0; for (int i = 0; i <= 1;...
1
0
['Java']
0
make-a-square-with-the-same-color
Easy Solution in C
easy-solution-in-c-by-sathurnithy-kbjo
Code
Sathurnithy
NORMAL
2025-01-05T13:55:01.964327+00:00
2025-01-05T13:55:01.964327+00:00
21
false
# Code ```c [] bool canMakeSquare(char** grid, int gridSize, int* gridColSize) { for(int i=0; i<2; i++){ for(int j=0; j<2; j++){ int gridSumWhite = (grid[i][j] == 'W' ? 1:0) + (grid[i][j+1] == 'W' ? 1:0) + (grid[i+1][j] == 'W' ? 1:0) + (grid[i+1][j+1] == 'W' ? 1:0); ...
1
0
['C']
0
make-a-square-with-the-same-color
C
c-by-pavithrav25-m8yn
IntuitionApproachComplexity Time complexity: Space complexity: Code
pavithrav25
NORMAL
2025-01-02T16:15:35.614695+00:00
2025-01-02T16:15:35.614695+00:00
29
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
1
0
['C']
0
make-a-square-with-the-same-color
Simple Kotlin solution
simple-kotlin-solution-by-tamhuynhit-twwd
Intuition\nCheck each 2x2 square, if it has 3 \'B\' or 3 \'W\' then it\'s valid and return True immediately.\n\nThere is special cases where there is an already
tamhuynhit
NORMAL
2024-08-24T06:35:19.096910+00:00
2024-08-24T06:35:19.096931+00:00
4
false
# Intuition\nCheck each 2x2 square, if it has 3 \'B\' or 3 \'W\' then it\'s valid and return True immediately.\n\nThere is special cases where there is an already full \'B\'/\'W\' 2x2 square in the grid, so changing any other cell around it still make it valid.\n\n# Approach\nCheck every 2x2 square\nUse a variable to c...
1
0
['Array', 'Kotlin']
0
make-a-square-with-the-same-color
Check color count in all 2x2 grids
check-color-count-in-all-2x2-grids-by-an-qm3m
Intuition\nWe can check how many possible 2x2 grids can be made of 3x3 grid and then check the the B & W count in each block.\n\n# Approach\n4 such 2x2 grids ca
ankit88
NORMAL
2024-06-22T04:56:21.284021+00:00
2024-06-22T04:56:21.284051+00:00
21
false
# Intuition\nWe can check how many possible 2x2 grids can be made of 3x3 grid and then check the the B & W count in each block.\n\n# Approach\n4 such 2x2 grids can be made. Left-Top, Right-Top, Left-Bottom, Right-Bottom.\n* We iterate over 3x3 grid and just check in each grid how many black boxes are there.(We just nee...
1
0
['Java']
1
make-a-square-with-the-same-color
Fashionable Approach
fashionable-approach-by-baghyawati-senu
Complexity\n- Time complexity: O(1)\n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution:\n def canMakeSquare(self, g: List[List[str]]) -> bool:\n
Baghyawati
NORMAL
2024-05-08T11:42:38.219046+00:00
2024-05-08T11:42:38.219105+00:00
52
false
# Complexity\n- Time complexity: $$O(1)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution:\n def canMakeSquare(self, g: List[List[str]]) -> bool:\n return any((c:=Counter(g[i][j:j+2]+g[i+1][j:j+2]))[\'W\']<2 or c[\'B\']<2 for i in range(2) for j in range(2))\n```
1
0
['Array', 'Python3']
1
make-a-square-with-the-same-color
BEST C++ SOLUTION ✅✅
best-c-solution-by-rishu_raj5938-unv7
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Rishu_Raj5938
NORMAL
2024-05-03T04:22:00.891277+00:00
2024-05-03T04:22:00.891308+00:00
5
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['C++']
0
make-a-square-with-the-same-color
Simple and intuitive thought. Time Complexity O(N) and Space Complexity O(1)
simple-and-intuitive-thought-time-comple-zuwo
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ankurjeesingh310
NORMAL
2024-04-30T19:57:18.692083+00:00
2024-04-30T19:57:18.692114+00:00
266
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['Java']
0
make-a-square-with-the-same-color
Check Four Squares - Fastest way ( 39 ms )
check-four-squares-fastest-way-39-ms-by-e61h7
javascript\nvar canMakeSquare = function(grid) {\n if (checkSquare(0, 0) >= 3) return true\n if (checkSquare(1, 0) >= 3) return true\n if (checkSquare(
zemamba
NORMAL
2024-04-29T14:46:53.140990+00:00
2024-04-29T14:46:53.141015+00:00
62
false
```javascript\nvar canMakeSquare = function(grid) {\n if (checkSquare(0, 0) >= 3) return true\n if (checkSquare(1, 0) >= 3) return true\n if (checkSquare(0, 1) >= 3) return true\n if (checkSquare(1, 1) >= 3) return true\n return false\n\n function checkSquare(a, b) {\n black = 0, white = 0\n ...
1
0
['JavaScript']
0
make-a-square-with-the-same-color
Beat 100% easy condition based solution
beat-100-easy-condition-based-solution-b-qyrs
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Rsharma_09
NORMAL
2024-04-28T14:20:05.906343+00:00
2024-04-28T14:20:05.906430+00:00
161
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O...
1
0
['Matrix', 'C++']
0
make-a-square-with-the-same-color
Simple Python solution
simple-python-solution-by-antarab-o57q
\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n import numpy as np\n matrix = np.array(grid)\n for i in ra
antarab
NORMAL
2024-04-27T21:12:56.930633+00:00
2024-04-27T21:12:56.930677+00:00
370
false
```\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n import numpy as np\n matrix = np.array(grid)\n for i in range(0, len(matrix[0])):\n for j in range(0, len(matrix)):\n if i<2 and j<2:\n res=matrix[i:i+2,j:j+2]\n ...
1
0
['Matrix', 'Python3']
1
make-a-square-with-the-same-color
[Python] check 4 squares
python-check-4-squares-by-pbelskiy-nrqn
\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n \n def check(y, x):\n b = w = 0\n \n
pbelskiy
NORMAL
2024-04-27T20:13:21.100639+00:00
2024-04-27T20:13:21.100670+00:00
18
false
```\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n \n def check(y, x):\n b = w = 0\n \n for dy, dx in ((x, y), (x + 1, y), (x, y + 1), (x + 1, y +1)):\n if grid[dy][dx] == \'B\':\n b += 1\n e...
1
0
['Python']
0
make-a-square-with-the-same-color
Python3 || 1 line Solution
python3-1-line-solution-by-gbaian10-qwdc
\n# Code\npython\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n return any([grid[i][j], grid[i+1][j], grid[i][j+1], grid
gbaian10
NORMAL
2024-04-27T18:41:08.525520+00:00
2024-04-27T18:45:49.361275+00:00
156
false
\n# Code\n```python\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n return any([grid[i][j], grid[i+1][j], grid[i][j+1], grid[i+1][j+1]].count("B") != 2 for i in range(2) for j in range(2))\n \n```
1
0
['Python3']
0
make-a-square-with-the-same-color
|Brute Force || General Solution || C++
brute-force-general-solution-c-by-sujalg-85ya
\n\n# Code\n\n\nclass Solution {\npublic:\n bool hasValidSquare(vector<vector<char>>& grid) {\n for (int i = 0; i < 2; ++i) {\n for (int j
sujalgupta09
NORMAL
2024-04-27T18:39:15.216490+00:00
2024-04-27T18:39:15.216518+00:00
112
false
\n\n# Code\n```\n\nclass Solution {\npublic:\n bool hasValidSquare(vector<vector<char>>& grid) {\n for (int i = 0; i < 2; ++i) {\n for (int j = 0; j < 2; ++j) {\n if (grid[i][j] == grid[i+1][j] && grid[i][j] == grid[i][j+1] && grid[i][j] == grid[i+1][j+1]) {\n retu...
1
0
['C++']
0
make-a-square-with-the-same-color
Easy Java Solution || 0ms exec time
easy-java-solution-0ms-exec-time-by-kari-uujx
\n\n# Complexity\n- Time complexity:O(1)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n
karishmaagrawal
NORMAL
2024-04-27T17:33:34.790142+00:00
2024-04-27T17:33:34.790160+00:00
97
false
\n\n# Complexity\n- Time complexity:O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean canMakeSquare(char[][] grid) {\n for(int row=0;row<2;row++){\n for(int...
1
0
['Java']
2
make-a-square-with-the-same-color
C 0ms
c-0ms-by-fredo30400-dkm7
Code\n\nbool canMakeSquare(char** grid, int gridSize, int* gridColSize) {\n for(int i=0;i<2;i++){\n for(int j=0;j<2;j++){\n int cnt = 0;\n
fredo30400
NORMAL
2024-04-27T16:59:25.039297+00:00
2024-04-27T16:59:25.039316+00:00
50
false
# Code\n```\nbool canMakeSquare(char** grid, int gridSize, int* gridColSize) {\n for(int i=0;i<2;i++){\n for(int j=0;j<2;j++){\n int cnt = 0;\n if (grid[j][i]==\'W\'){cnt++;}\n if (grid[j+1][i]==\'W\'){cnt++;}\n if (grid[j+1][i+1]==\'W\'){cnt++;}\n if (gr...
1
0
['C']
1
make-a-square-with-the-same-color
📌📌✅ Beats 100.00% of users with Java💥💥
beats-10000-of-users-with-java-by-abinay-sizs
Brute Force Approach\n\n\n\n# Code\n\nclass Solution {\n public boolean canMakeSquare(char[][] grid) {\n int w=0,i,j,r=grid.length,c=grid[0].length;\n
Abinayaprakash
NORMAL
2024-04-27T16:20:52.494387+00:00
2024-04-27T16:20:52.494416+00:00
19
false
# Brute Force Approach\n\n![upvote.PNG](https://assets.leetcode.com/users/images/bb3b70f6-4cd3-4183-817b-156398661aeb_1714234847.4938195.png)\n\n# Code\n```\nclass Solution {\n public boolean canMakeSquare(char[][] grid) {\n int w=0,i,j,r=grid.length,c=grid[0].length;\n int b=0;\n for(i=0;i<=1;i...
1
0
['Java']
0
make-a-square-with-the-same-color
[C++] Simple Check on 4 Sub-Squares, 6ms, 19.4MB
c-simple-check-on-4-sub-squares-6ms-194m-xfrv
This problem is rather easy to pin down to a few base cases - basically we want that either the first, second, third or fourth possible inner square have an amo
Ajna2
NORMAL
2024-04-27T16:19:16.306590+00:00
2024-04-28T19:24:55.137373+00:00
28
false
This problem is rather easy to pin down to a few base cases - basically we want that either the first, second, third or fourth possible inner square have an amount of a specific `!= 2`, since that is the only case in which we cannot achieve a `4` changing AT MOST one other element.\n\nWe can check that rather brute-for...
1
0
['C++']
0
make-a-square-with-the-same-color
[C++][Time & Space = O(1)][Detailed Array Directional Solution]
ctime-space-o1detailed-array-directional-btwd
Intuition\n\n- Think about currentCell as one corner of square (2 X 2)\n- Consider all possible 2 X 2 square can be made from that current cell\n- Now apply log
karnalrohit
NORMAL
2024-04-27T16:10:37.986855+00:00
2024-04-27T16:10:37.986875+00:00
55
false
# Intuition\n\n- Think about currentCell as one corner of square (2 X 2)\n- Consider all possible 2 X 2 square can be made from that current cell\n- Now apply logic on all possible square that any square have all value as same or not.\n\n# Approach\n\n- Take currentCell as one cell of square\n- Now from oneCell you nee...
1
1
['C++']
0
make-a-square-with-the-same-color
✅Beats 100.00% 🔥 || Java || C++ || C# || Easy Explanation || Beginner Friendly🔥🔥🔥
beats-10000-java-c-c-easy-explanation-be-pgsn
\n# Intuition\nThe problem aims to determine whether it is possible to form a square using the given grid of characters. A square can be formed if there exists
Sayan98
NORMAL
2024-04-27T16:07:29.375701+00:00
2024-04-27T16:14:48.534470+00:00
76
false
![image.png](https://assets.leetcode.com/users/images/6574a62e-069d-48c9-91d8-58ea8ad162d6_1714234014.0509677.png)\n# Intuition\nThe problem aims to determine whether it is possible to form a square using the given grid of characters. A square can be formed if there exists a 2x2 subgrid in the given grid where all the ...
1
0
['Math', 'C++', 'Java', 'C#']
0
make-a-square-with-the-same-color
Java Clean Solution
java-clean-solution-by-shree_govind_jee-f49k
Complexity\n- Time complexity:O(2*2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co
Shree_Govind_Jee
NORMAL
2024-04-27T16:07:05.668913+00:00
2024-04-27T16:07:05.668948+00:00
250
false
# Complexity\n- Time complexity:$$O(2*2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public boolean canMakeSquare(char[][] grid) {\n int black=0, white=0;\n for(int i=0...
1
0
['Array', 'Math', 'Matrix', 'Java']
0
make-a-square-with-the-same-color
BEAT 100% with JAVA
beat-100-with-java-by-hoang_soict-lcm1
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
hoang_soict
NORMAL
2024-04-27T16:01:44.574632+00:00
2024-04-27T16:01:44.574661+00:00
186
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['Java']
0
make-a-square-with-the-same-color
Simple C++ code, no hardcoding.
simple-c-code-no-hardcoding-by-coolpeng0-dzgg
IntuitionI saw that as long all of the rows or all of the columns have alternating cells, then you cannot make a 2x2 matching area. No matter whether they start
coolpeng0
NORMAL
2025-04-08T00:45:43.942141+00:00
2025-04-08T00:45:43.942141+00:00
4
false
# Intuition I saw that as long all of the rows or all of the columns have alternating cells, then you cannot make a 2x2 matching area. No matter whether they start with white or black, there are 2 white cells and 2 black cells in each 2x2 area when the cells are alternating in each line. I'm pretty sure this solution ...
0
0
['C++']
1
make-a-square-with-the-same-color
Simple Swift Solution
simple-swift-solution-by-felisviridis-2h2k
Code
Felisviridis
NORMAL
2025-04-03T08:01:50.051312+00:00
2025-04-03T08:01:50.051312+00:00
1
false
![Screenshot 2025-04-03 at 11.00.26 AM.png](https://assets.leetcode.com/users/images/14b7e63e-5552-4b64-83b5-8dbc4e7e5229_1743667267.2295299.png) # Code ```swift [] class Solution { func canMakeSquare(_ grid: [[Character]]) -> Bool { for a in 0...1 { for b in 0...1 { var fill =...
0
0
['Array', 'Swift', 'Matrix']
0
make-a-square-with-the-same-color
CPP beats 100%
cpp-beats-100-by-hareeshghk-2iuf
IntuitionWe just need to check 4 squares. Luckily start position points for squares are same as direction we need to go from starting point. So used same direti
hareeshghk
NORMAL
2025-03-29T19:29:16.477711+00:00
2025-03-29T19:29:16.477711+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> We just need to check 4 squares. Luckily start position points for squares are same as direction we need to go from starting point. So used same diretionb 2D array for both. # Approach <!-- Describe your approach to solving the problem. -->...
0
0
['C++']
0
make-a-square-with-the-same-color
Runtime 100% beats, memory 100% beats solution in Kotlin
runtime-100-beats-memory-100-beats-solut-zc6u
IntuitionI found four possible square and solved the problemComplexity Time complexity: O(1) Space complexity: O(1) Code
ahmadali_ok
NORMAL
2025-03-27T06:50:37.569965+00:00
2025-03-27T06:50:37.569965+00:00
1
false
# Intuition I found four possible square and solved the problem # Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```kotlin [] class Solution { fun canMakeSquare(grid: Array<CharArray>): Boolean { var bHelper = 0 if (grid[0][0] == 'B') bHelper++ if (grid[0][1] == 'B') bHelper++ ...
0
0
['Kotlin']
0
make-a-square-with-the-same-color
Java; math approach; 0ms beats 100%; 41.4 MB beats 97%
java-math-approach-0ms-beats-100-414-mb-6y8x9
IntuitionThe first thing I thought was that I must have only 1 element of a color on a 2x2 "subsquare" (it implies we will have 3 elements of the other). If the
osmarcf
NORMAL
2025-03-19T23:45:54.537274+00:00
2025-03-19T23:45:54.537274+00:00
4
false
# Intuition The first thing I thought was that I must have only 1 element of a color on a 2x2 "subsquare" (it implies we will have 3 elements of the other). If there's only 1, then I can already return "true". If not, I have to check the other subsquares. For this specific problem, we have only 4 subsquares. Basically,...
0
0
['Java']
0
make-a-square-with-the-same-color
Easy to understand solution in Java. Beats 100 %
easy-to-understand-solution-in-java-beat-lglk
Complexity Time complexity: O(1) Space complexity: O(1) Code
Khamdam
NORMAL
2025-03-16T06:18:31.115225+00:00
2025-03-16T06:18:31.115225+00:00
6
false
# Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```java [] class Solution { public boolean canMakeSquare(char[][] grid) { return isValid(grid, 0, 0) || isValid(grid, 0, 1) || isValid(grid, 1, 0) || isValid(grid, 1, 1); } private boolean isValid(char[][] grid, i...
0
0
['Array', 'Matrix', 'Java']
0
make-a-square-with-the-same-color
Simple Counting
simple-counting-by-beken-waf6
IntuitionSimple CountingApproachSimple CountingComplexity Time complexity:O(1) Space complexity:O(1) Code
beken
NORMAL
2025-02-22T15:36:04.112398+00:00
2025-02-22T15:36:04.112398+00:00
7
false
# Intuition Simple Counting # Approach Simple Counting # Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```java [] class Solution { public boolean canMakeSquare(char[][] grid) { for(int y = 0; y < grid.length-1; y++) { for(int x = 0; x < grid[0].length-1; x++) { ...
0
0
['Array', 'Matrix', 'Java']
0
make-a-square-with-the-same-color
Brute Force Solution, T = O(1) and S = O(1)
brute-force-solution-t-o1-and-s-o1-by-pu-iej8
IntuitionIf the no. of 'B' or 'W' is greater than 2 in any of the square then return true.ApproachIn all the squares we compare if the no. of B or W is greater
PuruMohite
NORMAL
2025-02-20T16:38:08.154172+00:00
2025-02-20T16:38:08.154172+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> If the no. of 'B' or 'W' is greater than 2 in any of the square then return true. # Approach <!-- Describe your approach to solving the problem. --> In all the squares we compare if the no. of B or W is greater than 2. If for a square it is...
0
0
['C++']
0
make-a-square-with-the-same-color
Simple Java solution -> 0 ms Beats 100.00%
simple-java-solution-0-ms-beats-10000-by-jdkf
IntuitionApproachComplexity Time complexity: O(1) Space complexity: O(1) Code
DevelopersUsername
NORMAL
2025-02-10T08:10:18.195107+00:00
2025-02-10T08:10:18.195107+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```java [] class Solution { public boolean canMakeSquare(char[][] grid) { int center = ...
0
0
['Java']
0
make-a-square-with-the-same-color
Java solution
java-solution-by-java_developer-6u7p
null
Java_Developer
NORMAL
2025-02-02T21:36:40.274630+00:00
2025-02-02T21:36:40.274630+00:00
10
false
```java [] class Solution { public boolean canMakeSquare(char[][] grid) { for (int r = 0; r < 2; r++) { for (int c = 0; c < 2; c++) { int whiteTiles = 0; whiteTiles += grid[r][c] == 'W' ? 1 : 0; whiteTiles += grid[r][c + 1] == 'W' ? 1 : 0; ...
0
0
['Java']
0
make-a-square-with-the-same-color
Java&JS&TS Solution (JW)
javajsts-solution-jw-by-specter01wj-awhw
IntuitionApproachComplexity Time complexity: Space complexity: Code
specter01wj
NORMAL
2025-01-28T07:19:58.492614+00:00
2025-01-28T07:19:58.492614+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Array', 'Matrix', 'Enumeration', 'Java', 'TypeScript', 'JavaScript']
0
make-a-square-with-the-same-color
100% Beat || Rust
100-beat-rust-by-nocabris-3t1k
Intuitionsplit the 3x3 matrix in 4 2x2 matrices and just count if we got more than 3 'W' or less than 2 'W'ApproachComplexityCode
nocabris
NORMAL
2025-01-23T13:35:34.380731+00:00
2025-01-23T13:35:34.380731+00:00
5
false
# Intuition split the 3x3 matrix in 4 2x2 matrices and just count if we got more than 3 'W' or less than 2 'W' # Approach <!-- Describe your approach to solving the problem. --> # Complexity # Code ```rust [] impl Solution { pub fn can_make_square(grid: Vec<Vec<char>>) -> bool { for i in 0..4 { ...
0
0
['Rust']
0
make-a-square-with-the-same-color
Solution in C
solution-in-c-by-praveenkesava-rnos
IntuitionApproachComplexity Time complexity: Space complexity: Code
praveenkesava
NORMAL
2025-01-21T09:53:06.216265+00:00
2025-01-21T09:53:06.216265+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C']
0
make-a-square-with-the-same-color
Typescript ✅ 100%
typescript-100-by-kay-79-0fan
Code
Kay-79
NORMAL
2025-01-18T17:41:57.456816+00:00
2025-01-18T17:41:57.456816+00:00
3
false
# Code ```typescript [] function canMakeSquare(grid: string[][]): boolean { for (let i = 0; i < 2; i++) { for (let j = 0; j < 2; j++) { let countW = 0; let countB = 0; grid[i][j] === "B" ? countB++ : countW++; grid[i][j + 1] === "W" ? countW++ : countB++; ...
0
0
['TypeScript']
0
make-a-square-with-the-same-color
scala oneliner
scala-oneliner-by-vititov-w75a
null
vititov
NORMAL
2025-01-18T16:08:50.227687+00:00
2025-01-18T16:08:50.227687+00:00
1
false
```scala [] object Solution { def canMakeSquare(grid: Array[Array[Char]]): Boolean = ( for{i <- grid.indices.init; j <- grid.head.indices.init} yield { Iterator(grid(i)(j), grid(i)(j+1), grid(i+1)(j), grid(i+1)(j+1)) .map(_.compare('B').sign).sum} ).filterNot(_ == 2).nonEmpty } ```
0
0
['Scala']
0
make-a-square-with-the-same-color
CPP
cpp-by-algoace_84-dr89
IntuitionApproachComplexity Time complexity: Space complexity: Code
Chandan_84
NORMAL
2025-01-15T17:32:16.457393+00:00
2025-01-15T17:32:16.457393+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
make-a-square-with-the-same-color
make-a-square-with-the-same-color in c
make-a-square-with-the-same-color-in-c-b-r6wk
IntuitionApproachComplexity Time complexity: Space complexity: Code
Udaya_V
NORMAL
2025-01-15T09:56:48.907320+00:00
2025-01-15T09:56:48.907320+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C']
0
make-a-square-with-the-same-color
Make-a-square-with-the-same-color (In Java)
make-a-square-with-the-same-color-in-jav-83g4
Code
nishanthinimani525
NORMAL
2025-01-12T16:18:55.355338+00:00
2025-01-12T16:18:55.355338+00:00
7
false
# Code ```java [] class Solution { public boolean canMakeSquare(char[][] grid) { for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ int w = 0, b=0; if(grid[i][j] == 'B'){ b++; } else{ w++; ...
0
0
['Java']
0
make-a-square-with-the-same-color
Make a square with the Same Color - python3 solution
make-a-square-with-the-same-color-python-25a8
IntuitionApproachComplexity Time complexity: Space complexity: Code
ChaithraDee
NORMAL
2025-01-12T15:35:56.338476+00:00
2025-01-12T15:35:56.338476+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> O(1) - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> ...
0
0
['Python3']
0
make-a-square-with-the-same-color
Check Balanced Square probability in Grid Matrix
check-balanced-square-probability-in-gri-hpkw
IntuitionApproachI divided the 3x3 grid into four 2x2 subgrids and checked if any of them already contain all cells of the same color or can be made uniform by
traezeeofor
NORMAL
2025-01-12T09:31:59.098524+00:00
2025-01-12T09:31:59.098524+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach I divided the 3x3 grid into four 2x2 subgrids and checked if any of them already contain all cells of the same color or can be made uniform by changing at most one cell. I checked for conditions where three cells are the same co...
0
0
['TypeScript']
0
make-a-square-with-the-same-color
Can make the grid larger size(not only 3*3)
can-make-the-grid-larger-sizenot-only-33-54p1
IntuitionApproachComplexity Time complexity: Space complexity: Code
linda2024
NORMAL
2025-01-10T23:03:44.766708+00:00
2025-01-10T23:03:44.766708+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C#']
0
make-a-square-with-the-same-color
C++ | Easy to understand
c-easy-to-understand-by-aman786-lbee
Complexity Time complexity: O(1) Space complexity: O(1) Code
Aman786
NORMAL
2025-01-10T18:36:49.500037+00:00
2025-01-10T18:36:49.500037+00:00
1
false
# Complexity - Time complexity: $$O(1)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: $$O(1)$$ <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: bool canMakeSquare(vector<vector<char>>& grid) { int n = grid.size(), m=grid[0].size...
0
0
['C++']
0
make-a-square-with-the-same-color
Make a square with same color Solution in C
make-a-square-with-same-color-solution-i-f2dk
IntuitionApproachComplexity Time complexity: O(n) Space complexity: O(1) Code
Darsan20
NORMAL
2025-01-07T17:15:35.541004+00:00
2025-01-07T17:15:35.541004+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(n) - Space complexity: O(1) # Code ```c [] bool canMakeSquare(char** grid, int gridSize, int* gridColSize) { *gridColSize = 3; ...
0
0
['C']
0
make-a-square-with-the-same-color
3127. Make a Square with the Same Color
3127-make-a-square-with-the-same-color-b-c31q
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-07T07:07:45.405019+00:00
2025-01-07T07:07:45.405019+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
make-a-square-with-the-same-color
Easy Solution in Java
easy-solution-in-java-by-sathurnithy-zavo
Code
Sathurnithy
NORMAL
2025-01-05T14:00:55.939227+00:00
2025-01-05T14:00:55.939227+00:00
7
false
# Code ```java [] class Solution { public boolean canMakeSquare(char[][] grid) { for(int i=0; i<2; i++){ for(int j=0; j<2; j++){ int gridSumWhite = (grid[i][j] == 'W' ? 1:0) + (grid[i][j+1] == 'W' ? 1:0) + (grid[i+1][j] == 'W' ? 1:0) + (grid[i+1][...
0
0
['Java']
0
make-a-square-with-the-same-color
super easy solution / python / beats 100% ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧
super-easy-solution-python-beats-100-ddi-951s
Code
Orin_M
NORMAL
2025-01-05T10:41:47.022188+00:00
2025-01-05T10:41:47.022188+00:00
2
false
![image.png](https://assets.leetcode.com/users/images/b7d99f47-8527-48e8-9de0-fd97247ed51c_1736073423.4443333.png) # Code ```python [] class Solution(object): def canMakeSquare(self, grid): """ :type grid: List[List[str]] :rtype: bool """ for r in range(2): for c ...
0
0
['Python']
0
make-a-square-with-the-same-color
Easy Java Solution 100% beating in time-complexity 🧑‍💻
easy-java-solution-100-beating-in-time-c-r0ro
Intuition Identify Squares: The core idea is to efficiently check for existing squares or potential squares within the grid. Color Dominance: Focus on the major
yuvsingh7650
NORMAL
2025-01-04T12:57:10.363061+00:00
2025-01-04T12:57:10.363061+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> - **Identify Squares**: The core idea is to efficiently check for existing squares or potential squares within the grid. - **Color Dominance**: Focus on the majority color within each 2x2 sub-grid. If a sub-grid has three or four of the sam...
0
0
['Java']
0
make-a-square-with-the-same-color
<<easy c++ solution -beats 100%>>
easy-c-solution-beats-100-by-shaivya2918-n9nm
IntuitionApproachComplexity Time complexity: Space complexity: Code
shaivya291872
NORMAL
2024-12-24T10:19:28.699009+00:00
2024-12-24T10:19:28.699009+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
make-a-square-with-the-same-color
Easy solution || java || 100% beat
easy-solution-java-100-beat-by-subhash_k-k63f
IntuitionApproachComplexity Time complexity: Space complexity: Code
Subhash_kumar143
NORMAL
2024-12-21T08:28:53.713891+00:00
2024-12-21T08:28:53.713891+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
make-a-square-with-the-same-color
Java | Easy Solution | O(1) | 0ms | Beats 100%
java-easy-solution-o1-0ms-beats-100-by-a-uh5t
ApproachDivide the 3x3 grid into 4 possible 2x2 sub-grids: Top-left: (0,0), (0,1), (1,0), (1,1) Top-right: (0,1), (0,2), (1,1), (1,2) Bottom-left: (1,0), (1,1),
arti8190
NORMAL
2024-12-15T10:18:45.806207+00:00
2024-12-15T10:18:45.806207+00:00
8
false
\n# Approach\n\n**Divide the 3x3 grid into 4 possible 2x2 sub-grids:**\n\n* Top-left: (0,0), (0,1), (1,0), (1,1)\n* Top-right: (0,1), (0,2), (1,1), (1,2)\n* Bottom-left: (1,0), (1,1), (2,0), (2,1)\n* Bottom-right: (1,1), (1,2), (2,1), (2,2)\n\n**Check if one of these 2x2 grids can be converted to a single-color grid:**...
0
0
['Java']
0
make-a-square-with-the-same-color
Easiest Solution Beats 100%
easiest-solution-beats-100-by-mayankbish-16br
null
MayankBisht8630
NORMAL
2024-12-11T09:55:27.047137+00:00
2024-12-11T09:55:27.047137+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
make-a-square-with-the-same-color
Easy & Simple Solution to Check If Same Color 2x2 Square Is Possible
easy-simple-solution-to-check-if-same-co-455h
null
hassan21kh1996
NORMAL
2024-12-10T17:17:22.257336+00:00
2024-12-10T17:17:22.257336+00:00
3
false
# Intuition\nWe need to check all 2x2 subgrids within the 3x3 grid to see if it\'s possible to make a uniform 2x2 square (all \'B\' or all \'W\') by changing at most one cell. If a subgrid contains 3 or more cells of the same color, we can change the remaining cell to make it uniform.\n\n# Approach\n1. **Iterate throug...
0
0
['Python3']
0
make-a-square-with-the-same-color
Beats 100% - Super Simple Solution
beats-100-super-simple-solution-by-brend-gbof
null
brendanc490
NORMAL
2024-12-10T02:11:47.192402+00:00
2024-12-10T02:11:47.192402+00:00
4
false
# Intuition\nIn order to make a 2X2 square of all the same color, we need at least 3 of the tiles to be the same color in the 2x2 area. Here are the cases:\n\nO O\nO X\n\nO X\nO O\n\nO O\nX O\n\nX O\nO O\n\nYou might notice a pattern here, which is that they all form an L like shape. Therefore, we just need to look for...
0
0
['Python']
0
make-a-square-with-the-same-color
Understandable Python for 0ms (beside 17.41Mb)
understandable-python-for-0ms-beside-174-2m7s
Intuition\n Describe your first thoughts on how to solve this problem. \n\nYou only have to check the 4 2x2 square and count the number of color\n\n# Approach\n
Clums
NORMAL
2024-12-05T12:38:42.263908+00:00
2024-12-05T12:38:42.263953+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nYou only have to check the 4 2x2 square and count the number of color\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nTo simplify it you see that it\'s about any color and it needs at most 1 move (cause with 2 ...
0
0
['Python3']
0
make-a-square-with-the-same-color
Solves for any size grid
solves-for-any-size-grid-by-rezaman-h0vd
Intuition\nFind any 2x2 squares that are majority the same color.\n\n# Approach\n- Split the grid into multiple 2x2 grids.\n- Supports arbitrarily sized square
rezaman
NORMAL
2024-12-03T19:21:18.787178+00:00
2024-12-03T19:23:44.833182+00:00
0
false
# Intuition\nFind any 2x2 squares that are majority the same color.\n\n# Approach\n- Split the grid into multiple 2x2 grids.\n- Supports arbitrarily sized square grid\n- Check each individual grid for majority same color\n\n\n# Complexity\n- Time complexity: N-squared\n\n- Space complexity: $$2n$$\n\n# Code\n```ruby []...
0
0
['Ruby']
0
make-a-square-with-the-same-color
Iterate & Split
iterate-split-by-rezaman-492b
Intuition\nFind any 2x2 squares that are majority the same color.\n\n# Approach\n- Split the grid into multiple 2x2 grids. \n- Check each individual grid for ma
rezaman
NORMAL
2024-12-03T19:16:18.374650+00:00
2024-12-03T19:16:18.374683+00:00
0
false
# Intuition\nFind any 2x2 squares that are majority the same color.\n\n# Approach\n- Split the grid into multiple 2x2 grids. \n- Check each individual grid for majority same color\n\n# Complexity\n- Time complexity: N-squared\n\n- Space complexity: $$2n$$\n\n# Code\n```ruby []\n# @param {Character[][]} grid\n# @return ...
0
0
['Ruby']
0
make-a-square-with-the-same-color
Submission beat 100% of other submissions' runtime.
submission-beat-100-of-other-submissions-xpui
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Vishva-mitra
NORMAL
2024-11-26T10:41:31.344952+00:00
2024-11-26T10:41:31.344987+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
make-a-square-with-the-same-color
[Java] ✅ 0MS ✅ 100% ✅ FASTEST ✅ BEST ✅ CLEAN CODE
java-0ms-100-fastest-best-clean-code-by-o3fq5
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. As you have 9 cells (W and B), you can make a special submatrix (2x2)
StefanelStan
NORMAL
2024-11-15T05:00:26.299422+00:00
2024-11-15T05:00:26.299452+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. As you have 9 cells (W and B), you can make a special submatrix (2x2) only if that matrix does not have 2 W or 2B. \n2. Any other combination (0-4, 1-3, 3-1, 4-0) will make a special submatrix.\n\n# Complexity\n- Time com...
0
0
['Java']
0
make-a-square-with-the-same-color
Build-up pairs of pairs of sum of consecutive Bs and are any not 2?
build-up-pairs-of-pairs-of-sum-of-consec-5ice
Count up consecutive pairs of Bs\n2. Transpose so that ...\n3. Sum up consecutive counts of Bs and ...\n4. Is there any sum that isnt 2 (which would be a 2x2 su
czrpb
NORMAL
2024-11-15T00:24:21.250773+00:00
2024-11-15T00:24:21.250807+00:00
0
false
1. Count up consecutive pairs of Bs\n2. Transpose so that ...\n3. Sum up consecutive counts of Bs and ...\n4. Is there any sum that isnt 2 (which would be a 2x2 sub-grid of half Bs, half Ws)\n\n# Code\n```racket []\n(define/contract (can-make-square grid (n 2) (m 2))\n (-> (listof (listof char?)) boolean?)\n\n (defin...
0
0
['Racket']
0
make-a-square-with-the-same-color
3127. Make a Square with the Same Color
3127-make-a-square-with-the-same-color-b-1767
Complexity\nTime: O(N^2)\nSpace: O(1)\n\n# Code\npython []\nclass Solution(object):\n def canMakeSquare(self, grid):\n """\n :type grid: List[L
pasha_iden
NORMAL
2024-11-12T00:46:30.757208+00:00
2024-11-12T00:46:30.757242+00:00
3
false
# Complexity\nTime: $$O(N^2)$$\nSpace: $$O(1)$$\n\n# Code\n```python []\nclass Solution(object):\n def canMakeSquare(self, grid):\n """\n :type grid: List[List[str]]\n :rtype: bool\n """\n q=1\n for x in range(len(grid)-1):\n for y in range(len(grid[x])-1):\n ...
0
0
['Python']
0
make-a-square-with-the-same-color
Does a 2x2 view not have 2 Bs?
does-a-2x2-view-not-have-2-bs-by-czrpb-ddih
Create a 2x2 lens\n2. Whip it thru the matrix; lets call these views\n3. Exit with #t if a view is found to not have 2 Bs\n\n# Code\nracket []\n(define/contract
czrpb
NORMAL
2024-11-11T23:00:49.301848+00:00
2024-11-11T23:00:49.301903+00:00
2
false
1. Create a 2x2 lens\n2. Whip it thru the matrix; lets call these *view*s\n3. Exit with `#t` if a *view* is found to not have 2 `B`s\n\n# Code\n```racket []\n(define/contract (can-make-square grid (n 2) (m 2))\n (-> (listof (listof char?)) boolean?)\n\n (define is-B? (curry char=? #\\B))\n\n (define [build-lens (n n...
0
0
['Racket']
0
make-a-square-with-the-same-color
Easy C++ Code (Beats 100%)
easy-c-code-beats-100-by-ai1a_2310812-nwv0
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ai1a_2310812
NORMAL
2024-11-10T09:03:11.843378+00:00
2024-11-10T09:03:11.843405+00:00
0
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
make-a-square-with-the-same-color
Simple solution using python
simple-solution-using-python-by-priya_re-8ydu
Time complexity of O(1):\nThere is a simple trick, if the 2x2 matrix contains equal number of "B" and "W" then we can\'t change the matrix as perfect square.\n\
Priya_Reka_S
NORMAL
2024-11-06T12:56:44.830133+00:00
2024-11-06T12:56:44.830166+00:00
4
false
Time complexity of O(1):\nThere is a simple trick, if the 2x2 matrix contains equal number of "B" and "W" then we can\'t change the matrix as perfect square.\n\n# Code\n```python3 []\nclass Solution:\n def canMakeSquare(self, grid: List[List[str]]) -> bool:\n l1=[grid[0][1],grid[0][0],grid[1][0],grid[1][1]]\n...
0
0
['Python3']
0
make-a-square-with-the-same-color
Simple PHP solution
simple-php-solution-by-file2k-ym9e
Intuition\nCreate 2x2 squares array from 3x3 square. Loop thru 2x2 squares and check weather it\'s possible for any of them to have all 4 cells with the same co
file2k
NORMAL
2024-11-04T20:47:49.111193+00:00
2024-11-04T20:47:49.111220+00:00
3
false
# Intuition\nCreate 2x2 squares array from 3x3 square. Loop thru 2x2 squares and check weather it\'s possible for any of them to have all 4 cells with the same color. \n\n# Approach\nOuter loops with iterators "i" and "j" are used for navigating 2x2 squares. Inner loops with iterators "k" and "l" are used for navigatin...
0
0
['PHP']
0
make-a-square-with-the-same-color
Java 0ms beats 100%, check all 2x2 subgrids and early return upon success
java-0ms-beats-100-check-all-2x2-subgrid-0sl3
Intuition\n Describe your first thoughts on how to solve this problem. \nIf a 2x2 subgrid has all one color, or 3 of one color, then we can have a 2x2 of 1 colo
texastim
NORMAL
2024-11-04T06:34:03.871096+00:00
2024-11-04T06:34:03.871158+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf a 2x2 subgrid has all one color, or 3 of one color, then we can have a 2x2 of 1 color with at most one change. If 2x2 subgrid has 2 of each color, we can\'t.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSyste...
0
0
['Java']
0
make-a-square-with-the-same-color
Beat 100% with Cpp
beat-100-with-cpp-by-carfel14-09l1
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
carfel14
NORMAL
2024-11-03T03:42:27.874779+00:00
2024-11-03T03:42:27.874825+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
make-a-square-with-the-same-color
POO Solution in Python
poo-solution-in-python-by-astros-5x57
Intuition\nThe solution is overcomplicated, but it is elegant :-P\n\n# Code\npython3 []\nclass Colors:\n def __init__(self, white: int, black: int):\n
Astros
NORMAL
2024-10-30T13:15:08.628909+00:00
2024-10-30T13:15:08.628935+00:00
2
false
# Intuition\nThe solution is overcomplicated, but it is elegant :-P\n\n# Code\n```python3 []\nclass Colors:\n def __init__(self, white: int, black: int):\n self.white = white\n self.black = black\n \n def is_possible(self) -> bool:\n return self.white in [3, 4] or self.black in [3, 4]\n\nc...
0
0
['Python3']
0
make-a-square-with-the-same-color
Easy
easy-by-shanku1999-q3ip
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
shanku1999
NORMAL
2024-10-23T09:46:53.971648+00:00
2024-10-23T09:46:53.971681+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
make-a-square-with-the-same-color
a new one
a-new-one-by-ianard-z332
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
IanArd
NORMAL
2024-10-21T19:15:33.480506+00:00
2024-10-21T19:15:33.480537+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Rust']
0
make-a-square-with-the-same-color
Customizable Solution | C++
customizable-solution-c-by-joao_ferrao-f29a
Complexity\n- Time complexity: O(1)\n\n- Space complexity: O(1)\n\n# Code\nC++ []\nclass Solution {\npublic:\n bool canMakeSquare(vector<vector<char>>& grid)
Joao_Ferrao
NORMAL
2024-10-16T15:07:51.447908+00:00
2024-10-16T15:07:51.447935+00:00
0
false
# Complexity\n- Time complexity: O(1)\n\n- Space complexity: O(1)\n\n# Code\n```C++ []\nclass Solution {\npublic:\n bool canMakeSquare(vector<vector<char>>& grid) {\n const int squareLength = 2;\n for(int i = 0; i < squareLength; ++i){\n for(int j = 0; j < squareLength; ++j){\n ...
0
0
['C++']
0
make-a-square-with-the-same-color
Brute Force Solution || JAVA
brute-force-solution-java-by-ashwinmurug-gufv
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ashwinmurugan46
NORMAL
2024-10-16T04:53:28.418856+00:00
2024-10-16T04:53:28.418901+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
make-a-square-with-the-same-color
C# simple solution
c-simple-solution-by-nzspider-ftiw
Code\ncsharp []\npublic class Solution {\n public bool CanMakeSquare(char[][] grid) {\n int row=3,col=3,r=0,c=0,b=0,w=0;\n var pos = new List<(
nzspider
NORMAL
2024-10-13T22:35:32.261739+00:00
2024-10-13T22:35:32.261838+00:00
7
false
# Code\n```csharp []\npublic class Solution {\n public bool CanMakeSquare(char[][] grid) {\n int row=3,col=3,r=0,c=0,b=0,w=0;\n var pos = new List<(int,int)>{(0,0),(0,1),(1,0),(1,1)};\n \n foreach(var (x, y) in pos){\n for(r=y;r<2+y;r++){\n for(c=x;c<2+x;c++){\n ...
0
0
['C#']
0
make-a-square-with-the-same-color
Python3 O(N ^ 4) Solution with counting (97.76% Runtime)
python3-on-4-solution-with-counting-9776-ogqy
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n\n# Approach\n Describe your approach to solving the problem. \n- Iteratively check
missingdlls
NORMAL
2024-10-10T11:51:09.848105+00:00
2024-10-10T11:51:09.848128+00:00
1
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n![image.png](https://assets.leetcode.com/users/images/07b4e686-1dc6-4264-a113-8877aa208ae2_1728560963.8037841.png)\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Iteratively check 4 adjacent cells and see if i...
0
0
['Array', 'Matrix', 'Counting', 'Python', 'Python3']
0
binary-tree-preorder-traversal
Accepted iterative solution in Java using stack.
accepted-iterative-solution-in-java-usin-9nab
Note that in this solution only right children are stored to stack.\n\n public List preorderTraversal(TreeNode node) {\n\t\tList list = new LinkedList();\n\t
pavel-shlyk
NORMAL
2014-12-29T15:03:10+00:00
2018-10-21T02:03:29.238021+00:00
77,976
false
Note that in this solution only right children are stored to stack.\n\n public List<Integer> preorderTraversal(TreeNode node) {\n\t\tList<Integer> list = new LinkedList<Integer>();\n\t\tStack<TreeNode> rights = new Stack<TreeNode>();\n\t\twhile(node != null) {\n\t\t\tlist.add(node.val);\n\t\t\tif (node.right != null...
347
7
[]
47
binary-tree-preorder-traversal
Very simple iterative Python solution
very-simple-iterative-python-solution-by-rhhu
Classical usage of stack's LIFO feature, very easy to grasp:\n\n \n def preorderTraversal(self, root):\n ret = []\n stack = [root]\n
clue
NORMAL
2015-01-27T04:17:27+00:00
2018-10-15T14:36:23.147933+00:00
36,928
false
Classical usage of stack's LIFO feature, very easy to grasp:\n\n \n def preorderTraversal(self, root):\n ret = []\n stack = [root]\n while stack:\n node = stack.pop()\n if node:\n ret.append(node.val)\n stack.append(node.right)\n ...
283
3
['Iterator', 'Python']
33
binary-tree-preorder-traversal
C++ Iterative, Recursive and Morris Traversal
c-iterative-recursive-and-morris-travers-5lbv
There are three solutions to this problem.\n\n 1. Iterative solution using stack --- O(n) time and O(n) space;\n 2. Recursive solution --- O(n) time and O(n) sp
jianchao-li
NORMAL
2015-05-21T16:31:34+00:00
2018-10-02T16:31:25.908094+00:00
27,836
false
There are three solutions to this problem.\n\n 1. Iterative solution using stack --- `O(n)` time and `O(n)` space;\n 2. Recursive solution --- `O(n)` time and `O(n)` space (function call stack);\n 3. Morris traversal --- `O(n)` time and `O(1)` space.\n\n**Iterative solution using stack**\n\n```cpp\nclass Solution {\npu...
229
2
['Stack', 'Recursion', 'Binary Tree', 'Iterator', 'C++']
18
binary-tree-preorder-traversal
Solution
solution-by-deleted_user-v7rj
C++ []\nclass Solution {\npublic:\n vector<int> preorderTraversal(TreeNode* root) {\n vector<int> preorder;\n stack<TreeNode*> stack;\n
deleted_user
NORMAL
2023-01-09T16:00:31.516361+00:00
2023-03-07T10:18:41.372462+00:00
15,432
false
```C++ []\nclass Solution {\npublic:\n vector<int> preorderTraversal(TreeNode* root) {\n vector<int> preorder;\n stack<TreeNode*> stack;\n if (root == NULL)\n return preorder;\n stack.push(root);\n while(!stack.empty()) {\n TreeNode* curr = stack.top();\n ...
221
0
['C++', 'Java', 'Python3']
3
binary-tree-preorder-traversal
3 Different Solutions
3-different-solutions-by-fabrizio3-1xgm
Recursive method with List as returning value:\n\n \tpublic List preorderTraversal(TreeNode root) {\n \t\tList pre = new LinkedList();\n \t\tif(root==n
fabrizio3
NORMAL
2015-04-22T07:50:47+00:00
2018-10-19T02:07:21.808809+00:00
43,107
false
Recursive method with List as returning value:\n\n \tpublic List<Integer> preorderTraversal(TreeNode root) {\n \t\tList<Integer> pre = new LinkedList<Integer>();\n \t\tif(root==null) return pre;\n \t\tpre.add(root.val);\n \t\tpre.addAll(preorderTraversal(root.left));\n \t\tpre.addAll(preorderTraversal...
220
4
['Recursion', 'Iterator', 'Java']
23
binary-tree-preorder-traversal
Python solutions (recursively and iteratively).
python-solutions-recursively-and-iterati-8emk
\n # recursively\n def preorderTraversal1(self, root):\n res = []\n self.dfs(root, res)\n return res\n \n def dfs(self,
oldcodingfarmer
NORMAL
2015-08-13T15:14:56+00:00
2018-09-24T23:32:41.072858+00:00
22,638
false
\n # recursively\n def preorderTraversal1(self, root):\n res = []\n self.dfs(root, res)\n return res\n \n def dfs(self, root, res):\n if root:\n res.append(root.val)\n self.dfs(root.left, res)\n self.dfs(root.right, res)\n \n # i...
170
1
['Recursion', 'Python']
14
binary-tree-preorder-traversal
【Video】Recursive Solution and Stack Solution
video-recursive-solution-and-stack-solut-pygs
Intuition\nWe should know how to implement inorder, preorder and postorder.\n\n# Solution Video\n\nhttps://youtu.be/9dTgOlzLDa0\n\n\u25A0 Timeline\n0:09 Explain
niits
NORMAL
2024-12-07T03:51:56.880619+00:00
2024-12-07T03:51:56.880643+00:00
8,862
false
# Intuition\nWe should know how to implement inorder, preorder and postorder.\n\n# Solution Video\n\nhttps://youtu.be/9dTgOlzLDa0\n\n\u25A0 Timeline\n`0:09` Explain Recursive Solution\n`1:02` Coding for Recursive Solution\n`2:08` Time Complexity and Space Complexity for Recursive Solution\n`2:27` Explain Stack Solution...
98
1
['Stack', 'Tree', 'Depth-First Search', 'Binary Tree', 'C++', 'Java', 'Python3', 'JavaScript']
0
binary-tree-preorder-traversal
✅[C++] EASY|| Beats100% || 3 Approach With explaination✅
c-easy-beats100-3-approach-with-explaina-fxde
\uD83C\uDFA5\uD83D\uDD25 Exciting News! Join my Coding Journey! Subscribe Now! \uD83D\uDD25\uD83C\uDFA5\n\n\uD83D\uDD17 Link in the leetcode profile \n\nNew cod
vishnoi29
NORMAL
2023-01-09T00:29:48.816065+00:00
2023-06-14T02:11:40.159956+00:00
12,531
false
\uD83C\uDFA5\uD83D\uDD25 Exciting News! Join my Coding Journey! Subscribe Now! \uD83D\uDD25\uD83C\uDFA5\n\n\uD83D\uDD17 Link in the leetcode profile \n\nNew coding channel alert! \uD83D\uDE80\uD83D\uDCBB Subscribe to unlock amazing coding content and tutorials. Help me reach 1K subs to start posting more videos! Join n...
97
2
['Stack', 'Recursion', 'C++']
4
binary-tree-preorder-traversal
Accepted code. Explaination with Algo.
accepted-code-explaination-with-algo-by-i69xy
Create an empty stack, Push root node to the stack.\n 2. Do following while stack is not empty.\n\n 2.1. pop an item from the stack and print it.\n \n 2.2. push
deepalaxmi
NORMAL
2014-08-23T21:24:07+00:00
2018-10-09T18:57:57.389248+00:00
15,584
false
1. Create an empty stack, Push root node to the stack.\n 2. Do following while stack is not empty.\n\n 2.1. pop an item from the stack and print it.\n \n 2.2. push the right child of popped item to stack.\n\n 2.3. push the left child of popped item to stack.\n\n \n\n\n> class Solution {\n> public:\n> v...
78
0
[]
10
binary-tree-preorder-traversal
4 solutions in c++
4-solutions-in-c-by-gogo93-3vsc
\n // recursive, but it's trivial...\n vector preorderTraversal(TreeNode root) {\n vector v;\n preTraversal(root, v);\n return v;\n
gogo93
NORMAL
2015-08-20T07:25:45+00:00
2018-08-30T09:40:50.439971+00:00
9,756
false
\n // recursive, but it's trivial...\n vector<int> preorderTraversal(TreeNode* root) {\n vector<int> v;\n preTraversal(root, v);\n return v;\n }\n void preTraversal(TreeNode* root, vector<int>& v){\n if(!root) return;\n v.push_back(root->val);\n preTraversal(root->l...
60
0
['C++']
3
binary-tree-preorder-traversal
Preorder Traversal Java solution both iteration and recursion
preorder-traversal-java-solution-both-it-0aqe
// recursive\n public class Solution {\n public List<Integer> preorderTraversal(TreeNode root) {\n List<Integer> result = new ArrayList<Int
king_yl
NORMAL
2015-10-20T02:13:17+00:00
2015-10-20T02:13:17+00:00
10,588
false
// recursive\n public class Solution {\n public List<Integer> preorderTraversal(TreeNode root) {\n List<Integer> result = new ArrayList<Integer>();\n if (root != null){\n result.add(root.val);\n result.addAll(preorderTraversal(root.left));\n ...
60
0
['Java']
3
binary-tree-preorder-traversal
Python 3 || 1-10 lines, 3 versions w/example || T/S: 98% / 99%
python-3-1-10-lines-3-versions-wexample-uai3r
\nThe iterative version, with example:\n\nclass Solution:\n def preorderTraversal(self, root: TreeNode) -> list[int]:\n\n
Spaulding_
NORMAL
2023-01-09T01:19:38.642836+00:00
2024-05-22T21:09:30.701958+00:00
7,861
false
\nThe iterative version, with example:\n```\nclass Solution:\n def preorderTraversal(self, root: TreeNode) -> list[int]:\n\n # Ex: root = [1, 2,None, 3,4]\n if not root: return [] # __1\n stack, ans = [root], [] # /\n ...
58
1
['Python', 'Python3']
2
binary-tree-preorder-traversal
Easy C++ solution using Stack
easy-c-solution-using-stack-by-yulingtia-mo3d
class Solution {\n public:\n vector<int> preorderTraversal(TreeNode *root) {\n if (root==NULL) {\n return vector<int>();\n }\n
yulingtianxia
NORMAL
2014-12-06T07:34:56+00:00
2018-10-17T15:12:18.679707+00:00
12,694
false
class Solution {\n public:\n vector<int> preorderTraversal(TreeNode *root) {\n if (root==NULL) {\n return vector<int>();\n }\n vector<int> result;\n stack<TreeNode *> treeStack;\n treeStack.push(root);\n while (!treeStack.empty()) {\n TreeNode *t...
54
0
[]
8
binary-tree-preorder-traversal
Java Solution with Explanation
java-solution-with-explanation-by-sartha-qa38
\n\n# Approach and Explanation ( Recursive )\n Describe your approach to solving the problem. \n1. A preorder traversal is a traversal order in which the root n
Sarthak_Singh_
NORMAL
2023-01-09T04:16:13.742817+00:00
2023-01-09T04:44:42.444406+00:00
4,566
false
\n\n# Approach and Explanation ( Recursive )\n<!-- Describe your approach to solving the problem. -->\n1. A preorder traversal is a traversal order in which the root node is visited first, followed by the left subtree, and then the right subtree. `The traversal order for a node is: root, left, right.`\n\n2. The code fi...
53
1
['Java']
2
binary-tree-preorder-traversal
132ms in JavaScript
132ms-in-javascript-by-linfongi-ktad
var preorderTraversal = function(root) {\n if (!root) return [];\n var result = [];\n var stack = [root];\n \n while(stack.length) {\n
linfongi
NORMAL
2015-05-21T01:03:21+00:00
2015-05-21T01:03:21+00:00
4,975
false
var preorderTraversal = function(root) {\n if (!root) return [];\n var result = [];\n var stack = [root];\n \n while(stack.length) {\n var node = stack.pop();\n result.push(node.val);\n if (node.right) stack.push(node.right);\n if (node.left) stack.push(node.left...
48
1
['JavaScript']
4
binary-tree-preorder-traversal
3 Iterative Solutions: Stack And Morris Traversal (Complexity Explained)
3-iterative-solutions-stack-and-morris-t-ugod
1 Stack-based:\nStack-based: \njava\npublic class Solution {\n public List<Integer> preorderTraversal(TreeNode root) {\n List<Integer> res = new Array
vegito2002
NORMAL
2017-08-13T21:41:34.002000+00:00
2018-10-12T03:20:40.021825+00:00
3,635
false
### 1 Stack-based:\nStack-based: \n```java\npublic class Solution {\n public List<Integer> preorderTraversal(TreeNode root) {\n List<Integer> res = new ArrayList<>();\n if (root == null)\n return res;\n Stack<TreeNode> s = new Stack<>();\n s.push(root);\n while (!s.isEmp...
41
1
[]
6
binary-tree-preorder-traversal
Java recursive and iterative solutions.
java-recursive-and-iterative-solutions-b-qunu
\n // recursively\n public List<Integer> preorderTraversal1(TreeNode root) {\n List<Integer> ret = new ArrayList<>();\n dfs(root, ret);\
oldcodingfarmer
NORMAL
2016-05-05T15:16:15+00:00
2016-05-05T15:16:15+00:00
4,020
false
\n // recursively\n public List<Integer> preorderTraversal1(TreeNode root) {\n List<Integer> ret = new ArrayList<>();\n dfs(root, ret);\n return ret;\n }\n \n private void dfs(TreeNode root, List<Integer> ret) {\n if (root != null) {\n ret.add(root.val);\n ...
33
0
['Recursion', 'Iterator', 'Java']
6
binary-tree-preorder-traversal
Preorder\u3001inorder\u3001postorder iterative solution by c++
preorderu3001inorderu3001postorder-itera-spe4
preorder:\n\n vector preorderTraversal(TreeNode root) {\n \tvector res;\n \tstd::stack temp;\n \twhile (root || !temp.empty()) {\n \t\twhile (roo
hustlx1
NORMAL
2016-05-03T13:22:17+00:00
2018-09-17T12:33:35.324240+00:00
4,216
false
preorder:\n\n vector<int> preorderTraversal(TreeNode* root) {\n \tvector<int> res;\n \tstd::stack<TreeNode*> temp;\n \twhile (root || !temp.empty()) {\n \t\twhile (root) {\n \t\t\ttemp.push(root);\n \t\t\tres.push_back(root->val);\n \t\t\troot = root->left;\n \t\t}\n \t\troot = temp.top();...
31
0
[]
2
binary-tree-preorder-traversal
C++ Solution || 100% faster || Iterative Solution
c-solution-100-faster-iterative-solution-2rmz
\nclass Solution {\npublic:\n vector<int> preorderTraversal(TreeNode* root) {\n vector<int> preorder;\n stack<TreeNode*> stack;\n if (ro
AlankarSaxena2712
NORMAL
2021-07-13T11:12:58.592023+00:00
2021-07-13T11:13:29.709375+00:00
3,445
false
```\nclass Solution {\npublic:\n vector<int> preorderTraversal(TreeNode* root) {\n vector<int> preorder;\n stack<TreeNode*> stack;\n if (root == NULL)\n return preorder;\n stack.push(root);\n while(!stack.empty()) {\n TreeNode* curr = stack.top();\n ...
26
0
['Stack', 'C', 'Iterator', 'C++']
5
binary-tree-preorder-traversal
3 Simple Python solutions
3-simple-python-solutions-by-shraddhapp-ggnc
Solution 1: Preorder traversal with stack\n\n\nclass Solution:\n def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]:\n ans = []\n
shraddhapp
NORMAL
2021-08-14T17:29:22.400501+00:00
2021-08-14T17:30:04.534860+00:00
3,067
false
##### Solution 1: Preorder traversal with stack\n\n```\nclass Solution:\n def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]:\n ans = []\n stack = [root]\n \n while stack:\n temp = stack.pop()\n \n if temp:\n ans.append(temp....
25
1
['Stack', 'Recursion', 'Python', 'Python3']
2
binary-tree-preorder-traversal
Python recursive and iterative solutions
python-recursive-and-iterative-solutions-z34v
Please see and vote for my solutions for these similar problems.\n94. Binary Tree Inorder Traversal\n144. Binary Tree Preorder Traversal\n145. Binary Tree Posto
otoc
NORMAL
2019-07-11T05:19:34.651622+00:00
2019-07-11T05:52:34.499313+00:00
3,457
false
Please see and vote for my solutions for these similar problems.\n[94. Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/discuss/332283/Python-recursive-and-iterative-solutions)\n[144. Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/d...
25
0
[]
3
binary-tree-preorder-traversal
✅ 🔥 0 ms Runtime Beats 100% User🔥|| Code Idea ✅ || Algorithm & Solving Step ✅ ||
0-ms-runtime-beats-100-user-code-idea-al-5stm
\n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n# I prefer Iterative Approach:\n\n### Intuition:\nPreorder traversal of a binary tree
Letssoumen
NORMAL
2024-12-04T00:23:01.820310+00:00
2024-12-04T00:23:01.820350+00:00
4,096
false
![Screenshot 2024-12-04 at 5.47.19\u202FAM.png](https://assets.leetcode.com/users/images/e1057879-14a1-4b5f-b514-60e4a12f1e46_1733271480.7984586.png)\n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n# I prefer Iterative Approach:\n\n### **Intuition:**\nPreorder traversal of a binary tree visits ...
23
1
['Stack', 'Tree', 'C++', 'Java', 'Python3']
0
binary-tree-preorder-traversal
C++ recursive simple solution || 0 ms, 100% faster
c-recursive-simple-solution-0-ms-100-fas-bht7
C++ :\n\n\nvoid preorderTraversalHelper(TreeNode* root, vector<int> &res) {\n\tif(root)\n\t{\n\t\tres.push_back(root -> val); \n\n\t\tif(root -> left)
TovAm
NORMAL
2021-10-07T10:54:16.705950+00:00
2021-10-07T10:54:16.705984+00:00
1,997
false
**C++ :**\n\n```\nvoid preorderTraversalHelper(TreeNode* root, vector<int> &res) {\n\tif(root)\n\t{\n\t\tres.push_back(root -> val); \n\n\t\tif(root -> left)\n\t\t\tpreorderTraversalHelper(root -> left, res);\n\n\t\tif(root -> right)\n\t\t\tpreorderTraversalHelper(root -> right, res);\n\t}\n\n\treturn;\n}\n\n...
23
1
['Recursion', 'C', 'C++']
3
binary-tree-preorder-traversal
Easy C++ Solution with Explaination
easy-c-solution-with-explaination-by-lon-5jvg
AN UPVOTE WOULD BE HIGHLY APPRECIATED !!!\n\nOverload the comments section with doubts and praises if you have.!!!\n\nTime Complexity: O(n)\nSpace Complexity: O
Longhorn_65
NORMAL
2021-05-29T12:48:49.170617+00:00
2021-05-29T12:49:46.326568+00:00
1,155
false
**AN UPVOTE WOULD BE HIGHLY APPRECIATED !!!**\n\n*Overload the comments section with doubts and praises if you have.!!!*\n\nTime Complexity: O(n)\nSpace Complexity: O(n)\n\n```\nclass Solution {\npublic:\n// Declairing global variable *ans* so that we don\'t declare it again and again and affect the SC by some factors\...
21
1
['C', 'C++']
2