一、二维数组转一维数组 [ [a, b] ] => [ c, d ]
一维数组的 index = row * 二维下标x + 二维下标y
一维数组转二维数组 matrix = [ [a, b] ]
二维下标 X = Math.floor(index / row)
二维下标 Y = Math.floor(index % row)
/**
* @param {number[][]} matrix
* @param {number} target
* @return {boolean}
*/
var searchMatrix = function (matrix, target) {
if(matrix === null || !matrix.length) return false
let row = matrix[0].length,
col = matrix.length,
l = 0,
r = (col - 1) * row + row - 1
while (l <= r) {
const m = Math.floor(l + (r - l) / 2)
const cur = matrix[Math.floor(m / row)][Math.floor(m % row)]
if(cur === target) return true
if(cur > target) {
r = m - 1
} else {
l = m + 1
}
}
return false
};