Skip to content

Commit e4c6e4b

Browse files
committed
feat: add solutions to lc problem: No.0598.Range Addition II
1 parent 603195a commit e4c6e4b

File tree

6 files changed

+135
-4
lines changed

6 files changed

+135
-4
lines changed

solution/0500-0599/0598.Range Addition II/README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ M 中最大的整数是 2, 而且 M 中有4个值为2的元素。因此返回 4
4646
<li>操作数目不超过 10000。</li>
4747
</ol>
4848

49-
5049
## 解法
5150

5251
<!-- 这里可写通用的实现逻辑 -->
@@ -58,15 +57,62 @@ M 中最大的整数是 2, 而且 M 中有4个值为2的元素。因此返回 4
5857
<!-- 这里可写当前语言的特殊实现逻辑 -->
5958

6059
```python
61-
60+
class Solution:
61+
def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:
62+
for a, b in ops:
63+
m = min(m, a)
64+
n = min(n, b)
65+
return m * n
6266
```
6367

6468
### **Java**
6569

6670
<!-- 这里可写当前语言的特殊实现逻辑 -->
6771

6872
```java
73+
class Solution {
74+
public int maxCount(int m, int n, int[][] ops) {
75+
for (int[] op : ops) {
76+
m = Math.min(m, op[0]);
77+
n = Math.min(n, op[1]);
78+
}
79+
return m * n;
80+
}
81+
}
82+
```
83+
84+
### **C++**
85+
86+
```cpp
87+
class Solution {
88+
public:
89+
int maxCount(int m, int n, vector<vector<int>>& ops) {
90+
for (auto op : ops) {
91+
m = min(m, op[0]);
92+
n = min(n, op[1]);
93+
}
94+
return m * n;
95+
}
96+
};
97+
```
6998
99+
### **Go**
100+
101+
```go
102+
func maxCount(m int, n int, ops [][]int) int {
103+
for _, op := range ops {
104+
m = min(m, op[0])
105+
n = min(n, op[1])
106+
}
107+
return m * n
108+
}
109+
110+
func min(a, b int) int {
111+
if a < b {
112+
return a
113+
}
114+
return b
115+
}
70116
```
71117

72118
### **...**

solution/0500-0599/0598.Range Addition II/README_EN.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,67 @@
4242
<li><code>1 &lt;= b<sub>i</sub> &lt;= n</code></li>
4343
</ul>
4444

45-
4645
## Solutions
4746

4847
<!-- tabs:start -->
4948

5049
### **Python3**
5150

5251
```python
53-
52+
class Solution:
53+
def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:
54+
for a, b in ops:
55+
m = min(m, a)
56+
n = min(n, b)
57+
return m * n
5458
```
5559

5660
### **Java**
5761

5862
```java
63+
class Solution {
64+
public int maxCount(int m, int n, int[][] ops) {
65+
for (int[] op : ops) {
66+
m = Math.min(m, op[0]);
67+
n = Math.min(n, op[1]);
68+
}
69+
return m * n;
70+
}
71+
}
72+
```
73+
74+
### **C++**
75+
76+
```cpp
77+
class Solution {
78+
public:
79+
int maxCount(int m, int n, vector<vector<int>>& ops) {
80+
for (auto op : ops) {
81+
m = min(m, op[0]);
82+
n = min(n, op[1]);
83+
}
84+
return m * n;
85+
}
86+
};
87+
```
5988
89+
### **Go**
90+
91+
```go
92+
func maxCount(m int, n int, ops [][]int) int {
93+
for _, op := range ops {
94+
m = min(m, op[0])
95+
n = min(n, op[1])
96+
}
97+
return m * n
98+
}
99+
100+
func min(a, b int) int {
101+
if a < b {
102+
return a
103+
}
104+
return b
105+
}
60106
```
61107

62108
### **...**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
int maxCount(int m, int n, vector<vector<int>>& ops) {
4+
for (auto op : ops) {
5+
m = min(m, op[0]);
6+
n = min(n, op[1]);
7+
}
8+
return m * n;
9+
}
10+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func maxCount(m int, n int, ops [][]int) int {
2+
for _, op := range ops {
3+
m = min(m, op[0])
4+
n = min(n, op[1])
5+
}
6+
return m * n
7+
}
8+
9+
func min(a, b int) int {
10+
if a < b {
11+
return a
12+
}
13+
return b
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution {
2+
public int maxCount(int m, int n, int[][] ops) {
3+
for (int[] op : ops) {
4+
m = Math.min(m, op[0]);
5+
n = Math.min(n, op[1]);
6+
}
7+
return m * n;
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:
3+
for a, b in ops:
4+
m = min(m, a)
5+
n = min(n, b)
6+
return m * n

0 commit comments

Comments
 (0)