Leftmost One
Given a 2D array, and each line has only0
and1
, the front part is0
, and the latter part is1
. Find the number of columns in the leftmost1
of all the rows in the array.
Example
Given arr =[[0,0,0,1],[1,1,1,1]]
, return0
.
Given arr =[[0,0,0,1],[0,1,1,1]]
, return1
.
Notice
The number of rows in the array and the number of columns do not exceed
1000
In order to limit the time complexity, your program will run
50000
times
分析
充分利用前面部分是0,后一部分是1二维数组的性质。找到第0行第一个1,然后往下找,是0就continue,是1的话往前找。时间复杂度O(m+n)。
Last updated