今年我想陪着 30 天之 28

1351. Count Negative Numbers in a Sorted Matrix

Given a m * n matrix grid which is sorted in non-increasing order both row-wise and column-wise.
Return the number of negative numbers in grid.

  • Example 1:
    Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
    Output: 8
    Explanation: There are 8 negatives number in the matrix.

  • Example 2:
    Input: grid = [[3,2],[1,0]]
    Output: 0

  • Example 3:
    Input: grid = [[1,-1],[-1,-1]]
    Output: 3

  • Example 4:
    Input: grid = [[-1]]
    Output: 1

var countNegatives = function(grid) {
    let num = 0;
    grid.flat().forEach(i => { 
      if(i<0) 
        num++; 
    })
    return num
};

<<:  谁温暖了资安部-27(反渗透)

>>:  Day28 火堆实作 - 模组参数

day 23 - 取号机 AUTO_INCREMENT(MYSQL) > INCR(Redis) > snowflake演算法

取号机制是专案中很常会使用到的项目。在我们的生活中小到饮料店的取餐单、银行的号码牌, 大到公文系统的...

完成便利贴程序第一版

补充完了必要的知识後,现在再回头看一下之前遇到的问题吧! 整合完 Firebase 之後发现了两个问...

锂电池与铅酸电池都会爆炸?

锂电池的关注点: 锂电池不及铅酸电池那样坚固。锂电池需要保护,以防止过度充电和过度放电。除此之外,它...

Golang + DevOps? Does DevOps Engineer Need to Learn Golang?"

Go for software developing. Go is becoming more fa...

RISC-V: Memory Store 指令

昨天已经把 Memory Write 的功能做完了, 今天稍微轻松一点,就来完成 Memory St...