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

Commit 0c757ca

Browse files
committed
1170 added
1 parent 64cb9eb commit 0c757ca

File tree

5 files changed

+107
-27
lines changed

5 files changed

+107
-27
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268
"yllw",
269269
"yollew",
270270
"yollow",
271+
"zaaaz",
271272
"zcpzvh",
272273
"zczpzfvdhx",
273274
"zczpzvdhx",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [1170. Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/)
2+
3+
Let's define a function f(s) over a non-empty string s, which calculates the frequency of the smallest character in s. For example, if s = "dcce" then f(s) = 2 because the smallest character is "c" and its frequency is 2.
4+
5+
Now, given string arrays queries and words, return an integer array answer, where each answer[i] is the number of words such that f(queries[i]) < f(W), where W is a word in words.
6+
7+
Example 1:
8+
9+
```text
10+
Input: queries = ["cbd"], words = ["zaaaz"]
11+
Output: [1]
12+
Explanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").
13+
```
14+
15+
Example 2:
16+
17+
```text
18+
Input: queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]
19+
Output: [1,2]
20+
Explanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").
21+
```
22+
23+
Constraints:
24+
25+
- `1 <= queries.length <= 2000`
26+
- `1 <= words.length <= 2000`
27+
- `1 <= queries[i].length, words[i].length <= 10`
28+
- `queries[i][j], words[i][j] are English lowercase letters.`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package problem1170
2+
3+
func numSmallerByFrequency(queries []string, words []string) []int {
4+
5+
return nil
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package problem1170
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
queries []string
12+
words []string
13+
ans []int
14+
}{
15+
16+
{
17+
[]string{"cbd"},
18+
[]string{"zaaaz"},
19+
[]int{1},
20+
},
21+
22+
{
23+
[]string{"bbb", "cc"},
24+
[]string{"a", "aa", "aaa", "aaaa"},
25+
[]int{1, 2},
26+
},
27+
28+
// 可以有多个 testcase
29+
}
30+
31+
func Test_numSmallerByFrequency(t *testing.T) {
32+
a := assert.New(t)
33+
34+
for _, tc := range tcs {
35+
a.Equal(tc.ans, numSmallerByFrequency(tc.queries, tc.words), "输入:%v", tc)
36+
}
37+
}
38+
39+
func Benchmark_numSmallerByFrequency(b *testing.B) {
40+
for i := 0; i < b.N; i++ {
41+
for _, tc := range tcs {
42+
numSmallerByFrequency(tc.queries, tc.words)
43+
}
44+
}
45+
}

leetcode.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 517,
4-
"Updated": "2019-08-25T16:49:57.101700069+08:00",
4+
"Updated": "2019-08-26T16:58:55.959451303+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 257,
@@ -925,7 +925,7 @@
925925
"ID": 75,
926926
"Title": "Sort Colors",
927927
"TitleSlug": "sort-colors",
928-
"PassRate": "42%",
928+
"PassRate": "43%",
929929
"Difficulty": "Medium",
930930
"IsAccepted": true,
931931
"IsPaid": false,
@@ -4753,7 +4753,7 @@
47534753
"ID": 394,
47544754
"Title": "Decode String",
47554755
"TitleSlug": "decode-string",
4756-
"PassRate": "45%",
4756+
"PassRate": "46%",
47574757
"Difficulty": "Medium",
47584758
"IsAccepted": true,
47594759
"IsPaid": false,
@@ -4969,7 +4969,7 @@
49694969
"ID": 412,
49704970
"Title": "Fizz Buzz",
49714971
"TitleSlug": "fizz-buzz",
4972-
"PassRate": "59%",
4972+
"PassRate": "60%",
49734973
"Difficulty": "Easy",
49744974
"IsAccepted": true,
49754975
"IsPaid": false,
@@ -6037,7 +6037,7 @@
60376037
"ID": 501,
60386038
"Title": "Find Mode in Binary Search Tree",
60396039
"TitleSlug": "find-mode-in-binary-search-tree",
6040-
"PassRate": "39%",
6040+
"PassRate": "40%",
60416041
"Difficulty": "Easy",
60426042
"IsAccepted": true,
60436043
"IsPaid": false,
@@ -6217,7 +6217,7 @@
62176217
"ID": 516,
62186218
"Title": "Longest Palindromic Subsequence",
62196219
"TitleSlug": "longest-palindromic-subsequence",
6220-
"PassRate": "47%",
6220+
"PassRate": "48%",
62216221
"Difficulty": "Medium",
62226222
"IsAccepted": true,
62236223
"IsPaid": false,
@@ -8317,7 +8317,7 @@
83178317
"ID": 691,
83188318
"Title": "Stickers to Spell Word",
83198319
"TitleSlug": "stickers-to-spell-word",
8320-
"PassRate": "39%",
8320+
"PassRate": "38%",
83218321
"Difficulty": "Hard",
83228322
"IsAccepted": true,
83238323
"IsPaid": false,
@@ -8641,7 +8641,7 @@
86418641
"ID": 718,
86428642
"Title": "Maximum Length of Repeated Subarray",
86438643
"TitleSlug": "maximum-length-of-repeated-subarray",
8644-
"PassRate": "47%",
8644+
"PassRate": "46%",
86458645
"Difficulty": "Medium",
86468646
"IsAccepted": true,
86478647
"IsPaid": false,
@@ -8677,7 +8677,7 @@
86778677
"ID": 721,
86788678
"Title": "Accounts Merge",
86798679
"TitleSlug": "accounts-merge",
8680-
"PassRate": "41%",
8680+
"PassRate": "42%",
86818681
"Difficulty": "Medium",
86828682
"IsAccepted": true,
86838683
"IsPaid": false,
@@ -8977,7 +8977,7 @@
89778977
"ID": 746,
89788978
"Title": "Min Cost Climbing Stairs",
89798979
"TitleSlug": "min-cost-climbing-stairs",
8980-
"PassRate": "47%",
8980+
"PassRate": "48%",
89818981
"Difficulty": "Easy",
89828982
"IsAccepted": true,
89838983
"IsPaid": false,
@@ -9001,7 +9001,7 @@
90019001
"ID": 748,
90029002
"Title": "Shortest Completing Word",
90039003
"TitleSlug": "shortest-completing-word",
9004-
"PassRate": "54%",
9004+
"PassRate": "55%",
90059005
"Difficulty": "Easy",
90069006
"IsAccepted": true,
90079007
"IsPaid": false,
@@ -9673,7 +9673,7 @@
96739673
"ID": 804,
96749674
"Title": "Unique Morse Code Words",
96759675
"TitleSlug": "unique-morse-code-words",
9676-
"PassRate": "74%",
9676+
"PassRate": "75%",
96779677
"Difficulty": "Easy",
96789678
"IsAccepted": true,
96799679
"IsPaid": false,
@@ -10669,7 +10669,7 @@
1066910669
"ID": 887,
1067010670
"Title": "Super Egg Drop",
1067110671
"TitleSlug": "super-egg-drop",
10672-
"PassRate": "24%",
10672+
"PassRate": "25%",
1067310673
"Difficulty": "Hard",
1067410674
"IsAccepted": true,
1067510675
"IsPaid": false,
@@ -11473,7 +11473,7 @@
1147311473
"ID": 954,
1147411474
"Title": "Array of Doubled Pairs",
1147511475
"TitleSlug": "array-of-doubled-pairs",
11476-
"PassRate": "35%",
11476+
"PassRate": "34%",
1147711477
"Difficulty": "Medium",
1147811478
"IsAccepted": true,
1147911479
"IsPaid": false,
@@ -12085,7 +12085,7 @@
1208512085
"ID": 1005,
1208612086
"Title": "Maximize Sum Of Array After K Negations",
1208712087
"TitleSlug": "maximize-sum-of-array-after-k-negations",
12088-
"PassRate": "50%",
12088+
"PassRate": "49%",
1208912089
"Difficulty": "Easy",
1209012090
"IsAccepted": true,
1209112091
"IsPaid": false,
@@ -12769,7 +12769,7 @@
1276912769
"ID": 1062,
1277012770
"Title": "Longest Repeating Substring",
1277112771
"TitleSlug": "longest-repeating-substring",
12772-
"PassRate": "51%",
12772+
"PassRate": "52%",
1277312773
"Difficulty": "Medium",
1277412774
"IsAccepted": false,
1277512775
"IsPaid": true,
@@ -13045,7 +13045,7 @@
1304513045
"ID": 1085,
1304613046
"Title": "Sum of Digits in the Minimum Number",
1304713047
"TitleSlug": "sum-of-digits-in-the-minimum-number",
13048-
"PassRate": "74%",
13048+
"PassRate": "73%",
1304913049
"Difficulty": "Easy",
1305013050
"IsAccepted": false,
1305113051
"IsPaid": true,
@@ -13213,7 +13213,7 @@
1321313213
"ID": 1099,
1321413214
"Title": "Two Sum Less Than K",
1321513215
"TitleSlug": "two-sum-less-than-k",
13216-
"PassRate": "61%",
13216+
"PassRate": "60%",
1321713217
"Difficulty": "Easy",
1321813218
"IsAccepted": false,
1321913219
"IsPaid": true,
@@ -13741,7 +13741,7 @@
1374113741
"ID": 1143,
1374213742
"Title": "Longest Common Subsequence",
1374313743
"TitleSlug": "longest-common-subsequence",
13744-
"PassRate": "57%",
13744+
"PassRate": "58%",
1374513745
"Difficulty": "Medium",
1374613746
"IsAccepted": true,
1374713747
"IsPaid": false,
@@ -13909,7 +13909,7 @@
1390913909
"ID": 1157,
1391013910
"Title": "Online Majority Element In Subarray",
1391113911
"TitleSlug": "online-majority-element-in-subarray",
13912-
"PassRate": "31%",
13912+
"PassRate": "32%",
1391313913
"Difficulty": "Hard",
1391413914
"IsAccepted": true,
1391513915
"IsPaid": false,
@@ -14005,7 +14005,7 @@
1400514005
"ID": 1165,
1400614006
"Title": "Single-Row Keyboard",
1400714007
"TitleSlug": "single-row-keyboard",
14008-
"PassRate": "85%",
14008+
"PassRate": "86%",
1400914009
"Difficulty": "Easy",
1401014010
"IsAccepted": false,
1401114011
"IsPaid": true,
@@ -14017,7 +14017,7 @@
1401714017
"ID": 1166,
1401814018
"Title": "Design File System",
1401914019
"TitleSlug": "design-file-system",
14020-
"PassRate": "62%",
14020+
"PassRate": "63%",
1402114021
"Difficulty": "Medium",
1402214022
"IsAccepted": false,
1402314023
"IsPaid": true,
@@ -14029,7 +14029,7 @@
1402914029
"ID": 1167,
1403014030
"Title": "Minimum Cost to Connect Sticks",
1403114031
"TitleSlug": "minimum-cost-to-connect-sticks",
14032-
"PassRate": "53%",
14032+
"PassRate": "55%",
1403314033
"Difficulty": "Medium",
1403414034
"IsAccepted": false,
1403514035
"IsPaid": true,
@@ -14041,7 +14041,7 @@
1404114041
"ID": 1168,
1404214042
"Title": "Optimize Water Distribution in a Village",
1404314043
"TitleSlug": "optimize-water-distribution-in-a-village",
14044-
"PassRate": "40%",
14044+
"PassRate": "44%",
1404514045
"Difficulty": "Hard",
1404614046
"IsAccepted": false,
1404714047
"IsPaid": true,
@@ -14053,7 +14053,7 @@
1405314053
"ID": 1169,
1405414054
"Title": "Invalid Transactions",
1405514055
"TitleSlug": "invalid-transactions",
14056-
"PassRate": "22%",
14056+
"PassRate": "24%",
1405714057
"Difficulty": "Easy",
1405814058
"IsAccepted": false,
1405914059
"IsPaid": false,
@@ -14077,7 +14077,7 @@
1407714077
"ID": 1171,
1407814078
"Title": "Remove Zero Sum Consecutive Nodes from Linked List",
1407914079
"TitleSlug": "remove-zero-sum-consecutive-nodes-from-linked-list",
14080-
"PassRate": "40%",
14080+
"PassRate": "44%",
1408114081
"Difficulty": "Medium",
1408214082
"IsAccepted": false,
1408314083
"IsPaid": false,
@@ -14089,7 +14089,7 @@
1408914089
"ID": 1172,
1409014090
"Title": "Dinner Plate Stacks",
1409114091
"TitleSlug": "dinner-plate-stacks",
14092-
"PassRate": "35%",
14092+
"PassRate": "40%",
1409314093
"Difficulty": "Hard",
1409414094
"IsAccepted": false,
1409514095
"IsPaid": false,

0 commit comments

Comments
 (0)