Skip to content

Commit 0ddead0

Browse files
author
Shuo
authored
Merge pull request #744 from openset/develop
Add: Range Addition II
2 parents f0300b3 + 4191d07 commit 0ddead0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Diff for: problems/range-addition-ii/range_addition_ii.go

+12
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
package problem598
2+
3+
func maxCount(m int, n int, ops [][]int) int {
4+
for _, op := range ops {
5+
if m > op[0] {
6+
m = op[0]
7+
}
8+
if n > op[1] {
9+
n = op[1]
10+
}
11+
}
12+
return m * n
13+
}

Diff for: problems/range-addition-ii/range_addition_ii_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
11
package problem598
2+
3+
import "testing"
4+
5+
type testType struct {
6+
m int
7+
n int
8+
ops [][]int
9+
want int
10+
}
11+
12+
func TestMaxCount(t *testing.T) {
13+
tests := [...]testType{
14+
{
15+
m: 3,
16+
n: 3,
17+
ops: [][]int{
18+
{2, 2},
19+
{3, 3},
20+
},
21+
want: 4,
22+
},
23+
}
24+
for _, tt := range tests {
25+
got := maxCount(tt.m, tt.n, tt.ops)
26+
if got != tt.want {
27+
t.Fatalf("in: %v, got: %v, want: %v", tt.m, got, tt.want)
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)