Find a number in sorted multidimentional array with binary search

后端 未结 10 904
深忆病人
深忆病人 2021-01-14 02:12

we got an increasing sorted multidimensional array for example:

int[][] mat = {{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}};

How can

10条回答
  •  一整个雨季
    2021-01-14 02:29

    public boolean Find(int[][] array, int number) { 
        int find = -1;
        for(int i = 0; i < N; i++) {
            find = binarySearch(array[i], number, 0, N);
            if(find != -1) { 
               return true; //the element is exist
            }
         }
         return false;//the element is not exist
    }
    

    Or you can revise this question it will help you a lot

提交回复
热议问题