/**
 * Treat the 2D array as a 1D array. matrix[index / cols][index % cols]
 * Time complexity: O(log(m * n))
 * Space complexity: O(1)
 */
class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        if (matrix.length == 0) {
            return false;
        }
        int l = 0;
        int r = matrix.length * matrix[0].length;
        int cols = matrix[0].length;
        while (l < r) {
            int m = l + (r - l) / 2;
            if (matrix[m / cols][m % cols] == target) {
                return true;
            } else if (matrix[m / cols][m % cols] > target) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        return false;
    }
}
@@ -1,10 +1,33 @@
 /
-**%0A *
+/ Solution: Binary Search%0A//
  Tre
@@ -74,17 +74,16 @@
 dex / co
-l
 s%5D%5Bindex
@@ -91,18 +91,18 @@
 %25 cols%5D%0A
- *
+//
  Time co
@@ -122,17 +122,15 @@
 og(m
- * 
+*
 n))%0A
- *
+//
  Spa
@@ -153,12 +153,8 @@
 (1)%0A
- */%0A
 clas
@@ -259,30 +259,16 @@
 th == 0)
- %7B%0A           
  return 
@@ -274,26 +274,16 @@
  false;%0A
-        %7D%0A
         
@@ -712,8 +712,9 @@
 %0A    %7D%0A%7D
+%0A

update Searcha2DMatrix.java