@@ -0,0 +1,1253 @@
+package advanced.scan.twopointers.lc240_searcha2dmatrix2;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Write an efficient algorithm that searches for a value in an m x n matrix.%0A * This matrix has the following properties:%0A * Integers in each row are sorted in ascending from left to right.%0A * Integers in each column are sorted in ascending from top to bottom.%0A * For example, consider the following matrix:%0A * %5B%0A *  %5B1,   4,  7, 11, 15%5D,%0A *  %5B2,   5,  8, 12, 19%5D,%0A *  %5B3,   6,  9, 16, 22%5D,%0A *  %5B10, 13, 14, 17, 24%5D,%0A *  %5B18, 21, 23, 26, 30%5D%0A * %5D%0A * Given target = 5, return true.%0A * Given target = 20, return false.%0A */%0Apublic class Solution %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(new Solution().searchMatrix(new int%5B%5D%5B%5D%7B%7B-1, 3%7D%7D, 1));%0A    %7D%0A%0A    public boolean searchMatrix(int%5B%5D%5B%5D matrix, int target) %7B%0A        int n = matrix.length;%0A        if (n == 0 %7C%7C matrix%5B0%5D.length == 0) %7B%0A            return false;%0A        %7D%0A%0A        int m = matrix%5B0%5D.length;%0A        for (int i = 0; i %3C n; i++) %7B%0A            if (matrix%5Bi%5D%5Bm - 1%5D %3C target) %7B%0A                continue;%0A            %7D%0A%0A            if (Arrays.binarySearch(matrix%5Bi%5D, target) != -1) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A%7D%0A

leetcode-240 search a 2D matrix 2