Find a number in sorted multidimentional array with binary search

后端 未结 10 988
深忆病人
深忆病人 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:48

    You could use the first number of each array (or the last) to find the element where your number could be present and then use binary search on that element to find if it's actually there.

提交回复
热议问题