|
| 1 | +<h2><a href="https://leetcode.com/problems/leftmost-column-with-at-least-a-one/">1428. Leftmost Column with at Least a One</a></h2><h3>Medium</h3><hr><div><p>A <strong>row-sorted binary matrix</strong> means that all elements are <code>0</code> or <code>1</code> and each row of the matrix is sorted in non-decreasing order.</p> |
| 2 | + |
| 3 | +<p>Given a <strong>row-sorted binary matrix</strong> <code>binaryMatrix</code>, return <em>the index (0-indexed) of the <strong>leftmost column</strong> with a 1 in it</em>. If such an index does not exist, return <code>-1</code>.</p> |
| 4 | + |
| 5 | +<p><strong>You can't access the Binary Matrix directly.</strong> You may only access the matrix using a <code>BinaryMatrix</code> interface:</p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <li><code>BinaryMatrix.get(row, col)</code> returns the element of the matrix at index <code>(row, col)</code> (0-indexed).</li> |
| 9 | + <li><code>BinaryMatrix.dimensions()</code> returns the dimensions of the matrix as a list of 2 elements <code>[rows, cols]</code>, which means the matrix is <code>rows x cols</code>.</li> |
| 10 | +</ul> |
| 11 | + |
| 12 | +<p>Submissions making more than <code>1000</code> calls to <code>BinaryMatrix.get</code> will be judged <em>Wrong Answer</em>. Also, any solutions that attempt to circumvent the judge will result in disqualification.</p> |
| 13 | + |
| 14 | +<p>For custom testing purposes, the input will be the entire binary matrix <code>mat</code>. You will not have access to the binary matrix directly.</p> |
| 15 | + |
| 16 | +<p> </p> |
| 17 | +<p><strong class="example">Example 1:</strong></p> |
| 18 | +<img alt="" src="https://assets.leetcode.com/uploads/2019/10/25/untitled-diagram-5.jpg" style="width: 81px; height: 81px;"> |
| 19 | +<pre><strong>Input:</strong> mat = [[0,0],[1,1]] |
| 20 | +<strong>Output:</strong> 0 |
| 21 | +</pre> |
| 22 | + |
| 23 | +<p><strong class="example">Example 2:</strong></p> |
| 24 | +<img alt="" src="https://assets.leetcode.com/uploads/2019/10/25/untitled-diagram-4.jpg" style="width: 81px; height: 81px;"> |
| 25 | +<pre><strong>Input:</strong> mat = [[0,0],[0,1]] |
| 26 | +<strong>Output:</strong> 1 |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p><strong class="example">Example 3:</strong></p> |
| 30 | +<img alt="" src="https://assets.leetcode.com/uploads/2019/10/25/untitled-diagram-3.jpg" style="width: 81px; height: 81px;"> |
| 31 | +<pre><strong>Input:</strong> mat = [[0,0],[0,0]] |
| 32 | +<strong>Output:</strong> -1 |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>rows == mat.length</code></li> |
| 40 | + <li><code>cols == mat[i].length</code></li> |
| 41 | + <li><code>1 <= rows, cols <= 100</code></li> |
| 42 | + <li><code>mat[i][j]</code> is either <code>0</code> or <code>1</code>.</li> |
| 43 | + <li><code>mat[i]</code> is sorted in non-decreasing order.</li> |
| 44 | +</ul> |
| 45 | +</div> |
0 commit comments