Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Sample

This file was deleted.

28 changes: 28 additions & 0 deletions Sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# // Time Complexity : O(log(m*n))
# // Space Complexity : O(1)
# // Did this code successfully run on Leetcode : Yes
# // Any problem you faced while coding this : No


# // Your code here along with comments explaining your approach in three sentences only
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
m = len(matrix)
n = len(matrix[0])
low = 0
high = (m*n) - 1
while low<=high:
mid = low + (high-low)//2

#convert index to position on matrix
r = mid//n
c = mid%n

if matrix[r][c] == target:
return True
elif matrix[r][c] > target:
high = mid - 1
else:
low = mid + 1

return False