Created
April 22, 2020 06:38
-
-
Save rejoycesong/36c87c15a178b00df2aa9a39a4871b80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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