package leetcode

func searchMatrix(matrix [][]int, target int) bool {
	for _, nums := range matrix {
		left, right := 0, len(nums)-1
		for left <= right {
			mid := (left + right) / 2
			if nums[mid] == target {
				return true
			} else if nums[mid] < target {
				left = mid + 1
			} else {
				right = mid - 1
			}
		}
	}
	return false
}

package leetcode

func searchMatrix(matrix [][]int, target int) bool {
	if matrix == nil || len(matrix) == 0 || len(matrix[0]) == 0 {
		return false
	}

	col, row := len(matrix[0])-1, 0
	for col >= 0 && row < len(matrix) {
		if matrix[row][col] == target {
			return true
		} else if matrix[row][col] < target {
			row++
		} else {
			col--
		}
	}
	return false
}

Fix 240. Search a 2D Matrix II to implement O(n+m) solution
Fix 240. Search a 2D Matrix II to implement O(n+m) solution
