Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. public class Solution {
  2. public boolean searchMatrix(int[][] matrix, int target) {
  3.  
  4. if(matrix==null || matrix.length<1 || matrix[0].length<1){
  5. return false;
  6. }
  7.  
  8. int col = matrix[0].length-1;
  9. int row = 0;
  10.  
  11. while(col>=0 && row<matrix.length){
  12. if(matrix[row][col]==target){
  13. return true;
  14. } else if(target<matrix[row][col]){
  15. col--;
  16. } else {
  17. row++;
  18. }
  19. }
  20.  
  21. return false;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement