# """# This is BinaryMatrix's API interface.# You should not implement it, or speculate about its implementation# """# class BinaryMatrix(object):# def get(self, row: int, col: int) -> int:# def dimensions(self) -> list[]:classSolution:defleftMostColumnWithOne(self,binaryMatrix:"BinaryMatrix")->int:m,n=binaryMatrix.dimensions()ans=nforiinrange(m):j=bisect_left(range(n),1,key=lambdak:binaryMatrix.get(i,k))ans=min(ans,j)return-1ifans>=nelseans
/** * // This is the BinaryMatrix's API interface. * // You should not implement it, or speculate about its implementation * interface BinaryMatrix { * public int get(int row, int col) {} * public List<Integer> dimensions {} * }; */classSolution{publicintleftMostColumnWithOne(BinaryMatrixbinaryMatrix){List<Integer>e=binaryMatrix.dimensions();intm=e.get(0),n=e.get(1);intans=n;for(inti=0;i<m;++i){intl=0,r=n;while(l<r){intmid=(l+r)>>1;if(binaryMatrix.get(i,mid)==1){r=mid;}else{l=mid+1;}}ans=Math.min(ans,l);}returnans>=n?-1:ans;}}
/** * // This is the BinaryMatrix's API interface. * // You should not implement it, or speculate about its implementation * class BinaryMatrix { * public: * int get(int row, int col); * vector<int> dimensions(); * }; */classSolution{public:intleftMostColumnWithOne(BinaryMatrix&binaryMatrix){autoe=binaryMatrix.dimensions();intm=e[0],n=e[1];intans=n;for(inti=0;i<m;++i){intl=0,r=n;while(l<r){intmid=(l+r)>>1;if(binaryMatrix.get(i,mid)){r=mid;}else{l=mid+1;}}ans=min(ans,l);}returnans>=n?-1:ans;}};
/** * // This is the BinaryMatrix's API interface. * // You should not implement it, or speculate about its implementation * type BinaryMatrix struct { * Get func(int, int) int * Dimensions func() []int * } */funcleftMostColumnWithOne(binaryMatrixBinaryMatrix)int{e:=binaryMatrix.Dimensions()m,n:=e[0],e[1]ans:=nfori:=0;i<m;i++{l,r:=0,nforl<r{mid:=(l+r)>>1ifbinaryMatrix.Get(i,mid)==1{r=mid}else{l=mid+1}}ans=min(ans,l)}ifans>=n{return-1}returnans}
/** * // This is the BinaryMatrix's API interface. * // You should not implement it, or speculate about its implementation * class BinaryMatrix { * get(row: number, col: number): number {} * * dimensions(): number[] {} * } */functionleftMostColumnWithOne(binaryMatrix:BinaryMatrix){const[m,n]=binaryMatrix.dimensions();letans=n;for(leti=0;i<m;++i){let[l,r]=[0,n];while(l<r){constmid=(l+r)>>1;if(binaryMatrix.get(i,mid)===1){r=mid;}else{l=mid+1;}}ans=Math.min(ans,l);}returnans>=n?-1:ans;}
/** * // This is the BinaryMatrix's API interface. * // You should not implement it, or speculate about its implementation * struct BinaryMatrix; * impl BinaryMatrix { * fn get(row: i32, col: i32) -> i32; * fn dimensions() -> Vec<i32>; * }; */implSolution{pubfnleft_most_column_with_one(binaryMatrix:&BinaryMatrix)->i32{lete=binaryMatrix.dimensions();letm=e[0]asusize;letn=e[1]asusize;letmutans=n;foriin0..m{let(mutl,mutr)=(0,n);whilel<r{letmid=(l+r)/2;ifbinaryMatrix.get(iasi32,midasi32)==1{r=mid;}else{l=mid+1;}}ans=ans.min(l);}ifans>=n{-1}else{ansasi32}}}
/** * // This is BinaryMatrix's API interface. * // You should not implement it, or speculate about its implementation * class BinaryMatrix { * public int Get(int row, int col) {} * public IList<int> Dimensions() {} * } */classSolution{publicintLeftMostColumnWithOne(BinaryMatrixbinaryMatrix){vare=binaryMatrix.Dimensions();intm=e[0],n=e[1];intans=n;for(inti=0;i<m;++i){intl=0,r=n;while(l<r){intmid=(l+r)>>1;if(binaryMatrix.Get(i,mid)==1){r=mid;}else{l=mid+1;}}ans=Math.Min(ans,l);}returnans>=n?-1:ans;}}