JavaScript solution
Search from top right corner\n\njs\n// Time O(m + n), rule out one row or one column each time\n// Space O(1)\n\nconst searchMatrix = (matrix, target) => {\n  i
Search from top right corner\n\n```js\n// Time O(m + n), rule out one row or one column each time\n// Space O(1)\n\nconst searchMatrix = (matrix, target) => {\n  if (matrix == null || matrix.length === 0) return false;\n  const h = matrix.length;\n  const w = matrix[0].length;\n\n  let i = 0;\n  let j = w - 1;\n  while (j >= 0 && i < h) {\n    if (target === matrix[i][j]) return true;\n    else if (target < matrix[i][j]) j--;\n    else i++;\n  }\n  return false;\n};\n```\n
[]