Skip to content

Instantly share code, notes, and snippets.

@rejoycesong
Created April 22, 2020 06:38
Show Gist options
  • Save rejoycesong/36c87c15a178b00df2aa9a39a4871b80 to your computer and use it in GitHub Desktop.
Save rejoycesong/36c87c15a178b00df2aa9a39a4871b80 to your computer and use it in GitHub Desktop.
class Solution:
def leftMostColumnWithOne(self, binaryMatrix: 'BinaryMatrix') -> int:
num_rows, num_cols = binaryMatrix.dimensions()[0], binaryMatrix.dimensions()[1]
x, y, last_seen_1 = 0, num_cols-1, "butts"
while x < num_rows and y >= 0:
if binaryMatrix.get(x, y) == 1:
last_seen_1 = y
y -= 1
elif binaryMatrix.get(x, y) == 0:
x += 1
return -1 if last_seen_1 == "butts" else last_seen_1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment