We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 070bec9 commit f1ed2bcCopy full SHA for f1ed2bc
Medium/Search a 2D Matrix.java
@@ -1,23 +1,18 @@
1
class Solution {
2
public boolean searchMatrix(int[][] matrix, int target) {
3
- if (matrix.length == 0 || matrix[0].length == 0) {
4
- return false;
5
- }
6
int rowIdx = matrix.length - 1;
7
int colIdx = matrix[0].length - 1;
8
while (rowIdx >= 0 && colIdx >= 0) {
9
- int val = matrix[rowIdx][colIdx];
10
- if (val == target) {
+ if (matrix[rowIdx][colIdx] == target) {
11
return true;
12
}
13
- if (val >= matrix[rowIdx][0]) {
+ if (matrix[rowIdx][colIdx] > target) {
14
colIdx--;
15
if (colIdx < 0) {
16
colIdx = matrix[0].length - 1;
17
rowIdx--;
18
19
20
- else {
+ } else {
21
22
23
0 commit comments