LeetCode 1351. Count Negative Numbers in a Sorted Matrix
题目链接
英文链接
中文链接
题目简介
给一个二维数组,其行和列都是按照从大到小的顺序排序,求其中服务的个数。
思路一
遍历数组
时间复杂度:O(n*n)
空间复杂度:O(1)
class Solution {
public int countNegatives(int[][] grid) {
int ans = 0;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j
原创
2020-08-25 21:52:42 ·
152 阅读 ·
0 评论