Most efficient way to search a sorted matrix?

后端 未结 9 1522
野的像风
野的像风 2020-12-29 14:02

I have an assignment to write an algorithm (not in any particular language, just pseudo-code) that receives a matrix [size: M x N] that is sorted in a way that all of it\'s

9条回答
  •  温柔的废话
    2020-12-29 14:20

    public static boolean find(int a[][],int rows,int cols,int x){
        int m=0;
        int n=cols-1;
    while(m=0){
        if(a[m][n]==x)
            return1;
        else if(a[m][n]>x)
            n--;
        else m++;
    }
    
    }
    

提交回复
热议问题