@@ -0,0 +1,1064 @@
+package leetcode.search_a_2d_matrix;%0A%0Apublic class Solution %7B%0A%09public boolean searchMatrix(int%5B%5D%5B%5D matrix, int target) %7B%0A%09%09if(matrix == null) return false;%0A%09%09if(matrix.length == 0) return false;%0A%09%09if(matrix%5B0%5D.length== 0) return false;%0A%09%09int height = matrix.length;%0A%09%09int width = matrix%5B0%5D.length;%0A%09%09int U = height * width;%0A%09%09int L = 0;%0A%09%09if(matrix%5B0%5D%5B0%5D == target) return true;%0A%09%09if(matrix%5B0%5D%5B0%5D %3E target %7C%7C matrix%5Bheight - 1%5D%5Bwidth - 1%5D %3C target) return false;%0A%09%09while(L + 1 %3C U)%7B%0A%09%09%09int mid = (L + U) / 2;%0A%09%09%09int x = mid / width;%0A%09%09%09int y = mid %25 width;%0A%09%09%09if(matrix%5Bx%5D%5By%5D == target) return true;%0A%09%09%09if(matrix%5Bx%5D%5By%5D %3E target) U = mid;%0A%09%09%09else L = mid;%0A%09%09%7D%0A%09%09return false;%0A    %7D%0A%09%0A%09public static void main(String%5B%5D args)%7B%0A%09%09final int height = 5;%0A%09%09final int width = 3;%0A%09%09int%5B%5D%5B%5D matrix = new int%5Bheight%5D%5Bwidth%5D;%0A%09%09for(int i = 0; i %3C height; i++)%7B%0A%09%09%09for(int j = 0; j %3C width; j++)%7B%0A%09%09%09%09matrix%5Bi%5D%5Bj%5D = (i * width + j) * 2;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09for(int i = -1; i %3C (height * width) * 2 + 1; i++)%7B%0A%09%09%09System.err.println(%22%22 + new Solution().searchMatrix(matrix, i));%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add java solution for 74. Search a 2D Matrix