当前位置:网站首页>The force deduction method summarizes the number of 1252 odd value cells
The force deduction method summarizes the number of 1252 odd value cells
2022-07-22 19:32:00 【Lost summer】
Directory links :
Force buckle programming problem - The solution sums up _ Share + Record -CSDN Blog
GitHub Synchronous question brushing items :
https://github.com/September26/java-algorithms
Original link : Power button
describe :
To give you one m x n Matrix , At the very beginning , The value in each cell is 0.
There is another two-dimensional index array indices,indices[i] = [ri, ci] Point to a position in the matrix , among ri and ci Respectively represent the specified row and column ( from 0 Numbered starting ).
Yes indices[i] Every position pointed , The following incremental operations should be performed at the same time :
ri All cells on the row , Add 1 .
ci All cells on the column , Add 1 .
Here you are. m、n and indices . Please finish executing all indices After the specified incremental operation , Back in the matrix Odd cells Number of .
Example 1:
Input :m = 2, n = 3, indices = [[0,1],[1,1]]
Output :6
explain : The initial matrix is [[0,0,0],[0,0,0]].
After the first incremental operation [[1,2,1],[0,1,0]].
The final matrix is [[1,3,1],[1,3,1]], There are 6 An odd number .
Example 2:
Input :m = 2, n = 2, indices = [[1,1],[0,0]]
Output :0
explain : The final matrix is [[2,2],[2,2]], There are no odd numbers in it .
Tips :
1 <= m, n <= 50
1 <= indices.length <= 100
0 <= ri < m
0 <= ci < n
source : Power button (LeetCode)
link :https://leetcode.cn/problems/cells-with-odd-values-in-a-matrix
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Their thinking :
* Their thinking : * This question is relatively simple , Find the last array according to the rules , Then calculate the odd number .
Code :
public class Solution1252 {
public int oddCells(int m, int n, int[][] indices) {
int[][] intss = new int[m][n];
for (int[] indice : indices) {
int i1 = indice[0];
int i2 = indice[1];
for (int i = 0; i < m; i++) {
intss[i][i2]++;
}
for (int i = 0; i < n; i++) {
intss[i1][i]++;
}
}
int result = 0;
for (int i = 0; i < intss.length; i++) {
for (int k = 0; k < intss[0].length; k++) {
if (intss[i][k] % 2 != 0) {
result++;
}
}
}
return result;
}
}
边栏推荐
- Glibc source code analysis
- Grafana panel - about conversion
- Leetcode daily question 2022/1/10-2022/1/16
- Introduction to arrays
- Leetcode daily question 2022/2/28-2022/3/6
- In his early 30s, he became a doctoral director of Fudan University. Chen Siming: I want to write both codes and poems
- 问一下,我用flinkCDC读取MySQL的binlog为什么datetime类型字段会早8个小时?
- 助力品牌洞察——消费者情绪行为分析
- Force deduction solution summary 1051 height checker
- LeetCode 每日一题 2021/11/22-2021/11/28
猜你喜欢
Oracle容器数据库的安装和使用
MySQL optimization enforces the use of indexes
How to adjust the spacing and edge distance of MATLAB plot subgraph (solved)
Rongyun x Xingzhi: exclusive Post-00 self social plot (including lottery)
Laravel solves [1045] access denied for user 'homestead' @ 'localhost' (usin g password: yes)
助力品牌洞察——消费者情绪行为分析
nacos持久化连接mysql数据库sm4加密方案
Don't let fear of marriage kill your happiness!
Introduction to arrays
"35 years old, I retired": This is the most reliable answer to the midlife crisis
随机推荐
LeetCode 每日一题 2022/1/10-2022/1/16
错过等一年!百度超级链数藏发行服务限时五折
grafana面板-关于转换
Oracle容器数据库的安装和使用
"35 years old, I retired": This is the most reliable answer to the midlife crisis
大佬们,在使用flinksql时候使用rocksdb需要配置什么吗?或者需要什么jar包吗
Force deduction solution summary 1108-ip address invalidation
Call() and apply()
Grafana panel - override field values
Leetcode: 197. rising temperature
MySQL optimization enforces the use of indexes
LeetCode 每日一题 2021/12/13-2021/12/19
LeetCode 每日一题 2022/1/3-2022/1/9
Go language learning: go language journey (V)
软件产业未来发展的几个趋势
Flutter 第一个程序Hello World!
What is "real time"
SQL 查询语句性能优化
Leetcode: 627. Change gender
Jackson parsing JSON detailed tutorial