FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/java/598_Range_Addition.java at master · jakehoare/leetcode · GitHub
jakehoare
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
30
Star
51
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
java
/
598_Range_Addition.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (21 loc) · 828 Bytes
Breadcrumbs
leetcode
/
java
/
598_Range_Addition.java
Copy path
File metadata and controls
23 lines (21 loc) · 828 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
https://leetcode.com/problems/range-addition-ii/
Given an m * n matrix M initialized with all 0's and several update operations.
Operations are represented by a 2D array, and each operation is represented by an array with two positive integers
a and b, which means M[i][j] should be added by one for all 0 <= i < a and 0 <= j < b.
You need to count and return the number of maximum integers in the matrix after performing all the operations.
Find minimum column and row that are updated.
Time - O(n)
Space - O(1)
*/
class
Solution
{
public
int
maxCount
(
int
m
,
int
n
,
int
[][]
ops
) {
int
sameRows
=
m
;
int
sameCols
=
n
;
for
(
int
[]
op
:
ops
) {
sameRows
=
Math
.
min
(
sameRows
,
op
[
0
]);
sameCols
=
Math
.
min
(
sameCols
,
op
[
1
]);
}
return
sameRows
*
sameCols
;
}
}
Back
|
FazBrowse Home
|
New Git URL