Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 6436f4f

Browse files
committed
974 added
1 parent f798254 commit 6436f4f

File tree

4 files changed

+86
-23
lines changed

4 files changed

+86
-23
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# [974. Subarray Sums Divisible by K](https://leetcode.com/problems/subarray-sums-divisible-by-k/)
2+
3+
Given an array A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K.
4+
5+
Example 1:
6+
7+
```text
8+
Input: A = [4,5,0,-2,-3,1], K = 5
9+
Output: 7
10+
Explanation: There are 7 subarrays with a sum divisible by K = 5:
11+
[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]
12+
```
13+
14+
Note:
15+
16+
- `1 <= A.length <= 30000`
17+
- `-10000 <= A[i] <= 10000`
18+
- `2 <= K <= 10000`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem0974
2+
3+
func subarraysDivByK(A []int, K int) int {
4+
5+
return 0
6+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package problem0974
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
A []int
12+
K int
13+
ans int
14+
}{
15+
16+
{
17+
[]int{4, 5, 0, -2, -3, 1},
18+
5,
19+
7,
20+
},
21+
22+
// 可以有多个 testcase
23+
}
24+
25+
func Test_subarraysDivByK(t *testing.T) {
26+
ast := assert.New(t)
27+
28+
for _, tc := range tcs {
29+
ast.Equal(tc.ans, subarraysDivByK(tc.A, tc.K), "输入:%v", tc)
30+
}
31+
}
32+
33+
func Benchmark_subarraysDivByK(b *testing.B) {
34+
for i := 0; i < b.N; i++ {
35+
for _, tc := range tcs {
36+
subarraysDivByK(tc.A, tc.K)
37+
}
38+
}
39+
}

leetcode.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
3-
"Ranking": 887,
4-
"Updated": "2019-05-19T14:29:22.822680387+08:00",
3+
"Ranking": 824,
4+
"Updated": "2019-05-20T20:32:37.102184025+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 235,
@@ -565,7 +565,7 @@
565565
"ID": 45,
566566
"Title": "Jump Game II",
567567
"TitleSlug": "jump-game-ii",
568-
"PassRate": "27%",
568+
"PassRate": "28%",
569569
"Difficulty": "Hard",
570570
"IsAccepted": true,
571571
"IsPaid": false,
@@ -829,7 +829,7 @@
829829
"ID": 67,
830830
"Title": "Add Binary",
831831
"TitleSlug": "add-binary",
832-
"PassRate": "38%",
832+
"PassRate": "39%",
833833
"Difficulty": "Easy",
834834
"IsAccepted": true,
835835
"IsPaid": false,
@@ -3217,7 +3217,7 @@
32173217
"ID": 266,
32183218
"Title": "Palindrome Permutation",
32193219
"TitleSlug": "palindrome-permutation",
3220-
"PassRate": "59%",
3220+
"PassRate": "60%",
32213221
"Difficulty": "Easy",
32223222
"IsAccepted": false,
32233223
"IsPaid": true,
@@ -4333,7 +4333,7 @@
43334333
"ID": 359,
43344334
"Title": "Logger Rate Limiter",
43354335
"TitleSlug": "logger-rate-limiter",
4336-
"PassRate": "64%",
4336+
"PassRate": "65%",
43374337
"Difficulty": "Easy",
43384338
"IsAccepted": false,
43394339
"IsPaid": true,
@@ -5041,7 +5041,7 @@
50415041
"ID": 418,
50425042
"Title": "Sentence Screen Fitting",
50435043
"TitleSlug": "sentence-screen-fitting",
5044-
"PassRate": "30%",
5044+
"PassRate": "31%",
50455045
"Difficulty": "Medium",
50465046
"IsAccepted": false,
50475047
"IsPaid": true,
@@ -5365,7 +5365,7 @@
53655365
"ID": 445,
53665366
"Title": "Add Two Numbers II",
53675367
"TitleSlug": "add-two-numbers-ii",
5368-
"PassRate": "49%",
5368+
"PassRate": "50%",
53695369
"Difficulty": "Medium",
53705370
"IsAccepted": true,
53715371
"IsPaid": false,
@@ -5845,7 +5845,7 @@
58455845
"ID": 485,
58465846
"Title": "Max Consecutive Ones",
58475847
"TitleSlug": "max-consecutive-ones",
5848-
"PassRate": "54%",
5848+
"PassRate": "55%",
58495849
"Difficulty": "Easy",
58505850
"IsAccepted": true,
58515851
"IsPaid": false,
@@ -7129,7 +7129,7 @@
71297129
"ID": 592,
71307130
"Title": "Fraction Addition and Subtraction",
71317131
"TitleSlug": "fraction-addition-and-subtraction",
7132-
"PassRate": "46%",
7132+
"PassRate": "47%",
71337133
"Difficulty": "Medium",
71347134
"IsAccepted": true,
71357135
"IsPaid": false,
@@ -7981,7 +7981,7 @@
79817981
"ID": 663,
79827982
"Title": "Equal Tree Partition",
79837983
"TitleSlug": "equal-tree-partition",
7984-
"PassRate": "38%",
7984+
"PassRate": "37%",
79857985
"Difficulty": "Medium",
79867986
"IsAccepted": false,
79877987
"IsPaid": true,
@@ -8617,7 +8617,7 @@
86178617
"ID": 716,
86188618
"Title": "Max Stack",
86198619
"TitleSlug": "max-stack",
8620-
"PassRate": "39%",
8620+
"PassRate": "40%",
86218621
"Difficulty": "Easy",
86228622
"IsAccepted": false,
86238623
"IsPaid": true,
@@ -9013,7 +9013,7 @@
90139013
"ID": 749,
90149014
"Title": "Contain Virus",
90159015
"TitleSlug": "contain-virus",
9016-
"PassRate": "41%",
9016+
"PassRate": "40%",
90179017
"Difficulty": "Hard",
90189018
"IsAccepted": true,
90199019
"IsPaid": false,
@@ -10021,7 +10021,7 @@
1002110021
"ID": 833,
1002210022
"Title": "Find And Replace in String",
1002310023
"TitleSlug": "find-and-replace-in-string",
10024-
"PassRate": "45%",
10024+
"PassRate": "46%",
1002510025
"Difficulty": "Medium",
1002610026
"IsAccepted": true,
1002710027
"IsPaid": false,
@@ -11005,7 +11005,7 @@
1100511005
"ID": 915,
1100611006
"Title": "Partition Array into Disjoint Intervals",
1100711007
"TitleSlug": "partition-array-into-disjoint-intervals",
11008-
"PassRate": "42%",
11008+
"PassRate": "43%",
1100911009
"Difficulty": "Medium",
1101011010
"IsAccepted": true,
1101111011
"IsPaid": false,
@@ -11641,7 +11641,7 @@
1164111641
"ID": 968,
1164211642
"Title": "Binary Tree Cameras",
1164311643
"TitleSlug": "binary-tree-cameras",
11644-
"PassRate": "34%",
11644+
"PassRate": "35%",
1164511645
"Difficulty": "Hard",
1164611646
"IsAccepted": true,
1164711647
"IsPaid": false,
@@ -12301,7 +12301,7 @@
1230112301
"ID": 1023,
1230212302
"Title": "Camelcase Matching",
1230312303
"TitleSlug": "camelcase-matching",
12304-
"PassRate": "56%",
12304+
"PassRate": "57%",
1230512305
"Difficulty": "Medium",
1230612306
"IsAccepted": false,
1230712307
"IsPaid": false,
@@ -12517,7 +12517,7 @@
1251712517
"ID": 1041,
1251812518
"Title": "Robot Bounded In Circle",
1251912519
"TitleSlug": "robot-bounded-in-circle",
12520-
"PassRate": "40%",
12520+
"PassRate": "41%",
1252112521
"Difficulty": "Easy",
1252212522
"IsAccepted": false,
1252312523
"IsPaid": false,
@@ -12553,7 +12553,7 @@
1255312553
"ID": 1044,
1255412554
"Title": "Longest Duplicate Substring",
1255512555
"TitleSlug": "longest-duplicate-substring",
12556-
"PassRate": "22%",
12556+
"PassRate": "23%",
1255712557
"Difficulty": "Hard",
1255812558
"IsAccepted": false,
1255912559
"IsPaid": false,
@@ -12577,7 +12577,7 @@
1257712577
"ID": 1046,
1257812578
"Title": "Last Stone Weight",
1257912579
"TitleSlug": "last-stone-weight",
12580-
"PassRate": "63%",
12580+
"PassRate": "64%",
1258112581
"Difficulty": "Easy",
1258212582
"IsAccepted": false,
1258312583
"IsPaid": false,
@@ -12589,7 +12589,7 @@
1258912589
"ID": 1047,
1259012590
"Title": "Remove All Adjacent Duplicates In String",
1259112591
"TitleSlug": "remove-all-adjacent-duplicates-in-string",
12592-
"PassRate": "55%",
12592+
"PassRate": "59%",
1259312593
"Difficulty": "Easy",
1259412594
"IsAccepted": false,
1259512595
"IsPaid": false,
@@ -12601,7 +12601,7 @@
1260112601
"ID": 1048,
1260212602
"Title": "Longest String Chain",
1260312603
"TitleSlug": "longest-string-chain",
12604-
"PassRate": "38%",
12604+
"PassRate": "43%",
1260512605
"Difficulty": "Medium",
1260612606
"IsAccepted": false,
1260712607
"IsPaid": false,
@@ -12613,7 +12613,7 @@
1261312613
"ID": 1049,
1261412614
"Title": "Last Stone Weight II",
1261512615
"TitleSlug": "last-stone-weight-ii",
12616-
"PassRate": "20%",
12616+
"PassRate": "32%",
1261712617
"Difficulty": "Medium",
1261812618
"IsAccepted": false,
1261912619
"IsPaid": false,

0 commit comments

Comments
 (0)