Order n Java easy solution


  • 2
    public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int i = 0;
        int j = matrix[0].length-1;
        while(i<=matrix.length-1 && j>=0){
            if(matrix[i][j] == target){
                return true;
            }else if(matrix[i][j] > target){
                j--;
            }else{
                i++;
            }
        }
        return false;
    }
    

    }


  • 0
    S

    It is O(m+n) solution. Not O(n). So, down vote.


  • 0
    J

    It is the same way. I think


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.