Given n and m which are the dimensions of a matrix initialized by zeros and given an array indices where indices[i] = [ri, ci]. For each pair of [ri, ci] you have to increment all cells in row ri and column ci by 1.

Return the number of cells with odd values in the matrix after applying the increment to all indices.

Example 1:

Input: n = 2, m = 3, indices = [[0,1],[1,1]]
Output: 6
Explanation: Initial matrix = [[0,0,0],[0,0,0]].
After applying first increment it becomes [[1,2,1],[0,1,0]].
The final matrix will be [[1,3,1],[1,3,1]] which contains 6 odd numbers.

Example 2:

Input: n = 2, m = 2, indices = [[1,1],[0,0]]
Output: 0
Explanation: Final matrix = [[2,2],[2,2]]. There is no odd number in the final matrix.

Constraints:

1 <= n <= 50
1 <= m <= 50
1 <= indices.length <= 100
0 <= indices[i][0] < n
0 <= indices[i][1] < m

python3:

 class Solution:
def oddCells(self, n: int, m: int, indices: List[List[int]]) -> int:
matrix = [[0] * m for _ in range(n)]
for ri, ci in indices:
for col in range(m):
matrix[ri][col] += 1
for row in range(n):
matrix[row][ci] += 1
rst = 0
for i in range(n):
for j in range(m):
if matrix[i][j] & 1:
rst += 1
return rst

[LeetCode]1252. Cells with Odd Values in a Matrix的更多相关文章

  1. 【leetcode】1252. Cells with Odd Values in a Matrix

    题目如下: Given n and m which are the dimensions of a matrix initialized by zeros and given an array ind ...

  2. &lt;LeetCode OJ&gt; 328. Odd Even Linked List

    328. Odd Even Linked List Total Accepted: 9271 Total Submissions: 24497 Difficulty: Easy Given a sin ...

  3. LeetCode 328. 奇偶链表(Odd Even Linked List)

    328. 奇偶链表 328. Odd Even Linked List 题目描述 给定一个单链表,把所有的奇数节点和偶数节点分别排在一起.请注意,这里的奇数节点和偶数节点指的是节点编号的奇偶性,而不是 ...

  4. LeetCode 562. Longest Line of Consecutive One in Matrix(在矩阵中最长的连续1)$

    Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horiz ...

  5. [LeetCode] 378. Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  6. 【LeetCode】329. Longest Increasing Path in a Matrix 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/longest- ...

  7. Leetcode:378. Kth Smallest Element in a Sorted Matrix

    题目: Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the ...

  8. 【Leetcode】【Medium】Search a 2D Matrix

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. 【leetcode刷题笔记】Search a 2D Matrix

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

随机推荐

  1. docker安装并运行mongo

    拉镜像: [mall@VM_0_7_centos ~]$ sudo docker pull mongo:3.2 [sudo] password for mall: 3.2: Pulling from ...

  2. Puppeteer最大化显示,分辨率自适应

    Puppeteer自适应分辨率,可以将defaultViewport设为null, 启动的时候还是半屏显示,点击最大化按钮,可以最大化显示. 这样分辨率能够自适应操作系统. 具体可看:https:// ...

  3. css选择器测试2-用ul和li简单排版

    之前的博文:测试了一些css样式的优先级,都是比较常见的选择器 ,这里测试一些其他一些选择方式. *:通配符,所有页面的元素都走这个.设置多个class:一个标签里不能有两个class,如果想要设置多 ...

  4. CSS製作動畫效果(Transition、Animation、Transform)

    CSS 2D Transforms https://www.w3schools.com/css/css3_2dtransforms.asp CSS 3D Transforms https://www. ...

  5. 九、Spring中使用@Value和@PropertySource为属性赋值

    首先回顾下在xml中我们是如何为spring的bean进行属性赋值呢? 大体是这样的 <bean id="person" class="com.atguigu.be ...

  6. STS,修改Ctrl+Shift+R匹配类的配置

    在使用STS(Spring Tools)时,每次通过Ctrl+Shift+R查询类时,会出来一堆不想看到的类.如下所示: 上面的.class文件和父项目中的.java文件,在匹配类时,是不想看到的. ...

  7. AVR单片机教程——按键动作

    上一篇教程中我们学习了如何读取按键状态.而按键的动作,比如单击,至少需要两个状态才能判定,长按.双击的判定更加复杂.今天我们来学习如何使用库函数判断按键单击,以及其实现原理. 我们要实现的是:当一个按 ...

  8. oracle数据库 TIMESTAMP(6)时间戳类型

    时间戳类型,参数6指的是表示秒的数字的小数点右边可以存储6位数字,最多9位.由于时间戳的精确度很高,我们也常常用来作为版本控制. 插入时,如下方式:insert into test4 values(t ...

  9. python之(TensorFlow)深度学习

    一.深度学习(DL, Deep Learning)是机器学习(ML, Machine Learning)领域中一个新的研究方向,它被引入机器学习使其更接近于最初的目标——人工智能(AI, Artifi ...

  10. spring boot 集成mybatis plus 含分页 完整教程

    一.添加依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus ...