Skip to content

Commit 1e97bea

Browse files
authored
Update Search a 2D Matrix - Leetcode 74.py
1 parent 6a45c13 commit 1e97bea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Search a 2D Matrix - Leetcode 74/Search a 2D Matrix - Leetcode 74.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
99
# Time: O(m * n)
1010
# Space: O(1)
1111

12+
# Brute Force Solution With (i, j) indices
13+
class Solution:
14+
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
15+
m, n = len(matrix), len(matrix[0])
16+
for i in range(m):
17+
for j in range(n):
18+
if target == matrix[i][j]:
19+
return True
20+
21+
return False
22+
# Time: O(m * n)
23+
# Space: O(1)
24+
1225
# Optimal Solution
1326
class Solution:
1427
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:

0 commit comments

Comments
 (0)