{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.
\n", "
Example 1:
\n", "\n", "Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]\n",
"Output: 8\n",
"Explanation: There are 8 negatives number in the matrix.\n",
"\n",
"\n",
"Example 2:
\n", "\n", "Input: grid = [[3,2],[1,0]]\n",
"Output: 0\n",
"\n",
"\n",
"Example 3:
\n", "\n", "Input: grid = [[1,-1],[-1,-1]]\n",
"Output: 3\n",
"\n",
"\n",
"Example 4:
\n", "\n", "Input: grid = [[-1]]\n",
"Output: 1\n",
"\n",
"\n",
"\n", "
Constraints:
\n", "\n", "m == grid.lengthn == grid[i].length1 <= m, n <= 100-100 <= grid[i][j] <= 100\n", "Source \n", "
Could you find an O(n + m) solution?