Skip to content

Commit 4d5d587

Browse files
committed
1252 solved.
1 parent ebfbe7d commit 4d5d587

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(cpp_1252)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_1252 main.cpp)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// Source : https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-07-11
4+
5+
#include <iostream>
6+
#include <vector>
7+
8+
using namespace std;
9+
10+
11+
/// Simulation
12+
/// Time Complexity: O(m * n * (m + n))
13+
/// Space Complexity: O(m * n)
14+
class Solution {
15+
public:
16+
int oddCells(int R, int C, vector<vector<int>>& indices) {
17+
18+
vector<vector<int>> matrix(R, vector<int>(C, 0));
19+
for(const vector<int>& e: indices){
20+
int r = e[0], c = e[1];
21+
for(int j = 0; j < C; j ++) matrix[r][j] ++;
22+
for(int i = 0; i < R; i ++) matrix[i][c] ++;
23+
}
24+
25+
int res = 0;
26+
for(int i = 0; i < R; i ++)
27+
for(int j = 0; j < C; j ++) res += matrix[i][j] % 2;
28+
return res;
29+
}
30+
};
31+
32+
33+
int main() {
34+
35+
return 0;
36+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
12011201
| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/) | [solution](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/solution/) | [C++](1001-1500/1249-Minimum-Remove-to-Make-Valid-Parentheses/cpp-1249/) | | |
12021202
| | | | | | |
12031203
| 1251 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
1204+
| 1252 | [Cells with Odd Values in a Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/) | [] | [C++](1001-1500/1252-Cells-with-Odd-Values-in-a-Matrix/cpp-1252/) | | |
12041205
| | | | | | |
12051206
| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid/) | [solution](https://leetcode.com/problems/shift-2d-grid/solution/) | [C++](1001-1500/1260-Shift-2D-Grid/cpp-1260/) | | |
12061207
| 1261 | [Find Elements in a Contaminated Binary Tree](https://leetcode.com/contest/weekly-contest-163/problems/find-elements-in-a-contaminated-binary-tree/) | [C++](1001-1500/1261-Find-Elements-in-a-Contaminated-Binary-Tree/cpp-1261/) | | | |

0 commit comments

Comments
 (0)