Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb25b34a

Browse files
refactor 1252
1 parent31813be commitb25b34a

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

‎src/main/java/com/fishercoder/solutions/_1252.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,11 @@
11
packagecom.fishercoder.solutions;
22

3-
/**
4-
* 1252. Cells with Odd Values in a Matrix
5-
*
6-
* 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.
7-
* Return the number of cells with odd values in the matrix after applying the increment to all indices.
8-
*
9-
* Example 1:
10-
* 0, 0, 0 1, 2, 1 1, 3, 1
11-
* 0, 0, 0 0, 1, 0 1, 3 ,1
12-
*
13-
* Input: n = 2, m = 3, indices = [[0,1],[1,1]]
14-
* Output: 6
15-
* Explanation: Initial matrix = [[0,0,0],[0,0,0]].
16-
* After applying first increment it becomes [[1,2,1],[0,1,0]].
17-
* The final matrix will be [[1,3,1],[1,3,1]] which contains 6 odd numbers.
18-
*
19-
* Example 2:
20-
* 0, 0 0, 1 2, 2
21-
* 0, 0 1, 2 2, 2
22-
*
23-
* Input: n = 2, m = 2, indices = [[1,1],[0,0]]
24-
* Output: 0
25-
* Explanation: Final matrix = [[2,2],[2,2]]. There is no odd number in the final matrix.
26-
*
27-
*
28-
* Constraints:
29-
* 1 <= n <= 50
30-
* 1 <= m <= 50
31-
* 1 <= indices.length <= 100
32-
* 0 <= indices[i][0] < n
33-
* 0 <= indices[i][1] < m
34-
* */
353
publicclass_1252 {
364
publicstaticclassSolution1 {
375
/**
386
* Time: O(m*n + k) where k is the length of indices
397
* Space: O(m*n)
40-
* */
8+
*/
419
publicintoddCells(intn,intm,int[][]indices) {
4210
int[][]matrix =newint[n][m];
4311
for (inti =0;i <indices.length;i++) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp