Leftmost Column with at Least a One
https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/530/week-3/3306/




Last updated
https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/530/week-3/3306/




Last updated
Input: mat = [[0,0],[1,1]]
Output: 0Input: mat = [[0,0],[0,1]]
Output: 1Input: mat = [[0,0],[0,0]]
Output: -1Input: mat = [[0,0,0,1],[0,0,1,1],[0,1,1,1]]
Output: 1# """
# This is BinaryMatrix's API interface.
# You should not implement it, or speculate about its implementation
# """
#class BinaryMatrix(object):
# def get(self, x: int, y: int) -> int:
# def dimensions(self) -> list[]:
class Solution:
def leftMostColumnWithOne(self, binaryMatrix: 'BinaryMatrix') -> int:
M, N = binaryMatrix.dimensions()
r, c = 0, N - 1
while r < M and c >= 0:
if binaryMatrix.get(r, c) == 0:
r += 1
else:
c -= 1
return c + 1 if c != N - 1 else -1