Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. class 2DSearch {
  2. public boolean searchMatrix(int[][] matrix, int target) {
  3. if (matrix.length == 0) return false;
  4. int i = 0;
  5. int j = matrix[0].length - 1;
  6.  
  7. while (i < matrix.length && j >= 0) {
  8. if (matrix[i][j] == target) {
  9. return true;
  10. } else if (matrix[i][j] > target) {
  11. j--;
  12. } else {
  13. i++;
  14. }
  15. }
  16. return false;
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement