Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit835a663

Browse files
refactor 1170
1 parent5021334 commit835a663

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

‎src/main/java/com/fishercoder/solutions/_1170.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,13 @@
22

33
importjava.util.Arrays;
44

5-
/**
6-
* 1170. Compare Strings by Frequency of the Smallest Character
7-
*
8-
* Let's define a function f(s) over a non-empty string s,
9-
* which calculates the frequency of the smallest character in s.
10-
* For example, if s = "dcce" then f(s) = 2 because the smallest character is "c" and its frequency is 2.
11-
* Now, given string arrays queries and words,
12-
* return an integer array answer,
13-
* where each answer[i] is the number of words such that f(queries[i]) < f(W), where W is a word in words.
14-
*
15-
* Example 1:
16-
* Input: queries = ["cbd"], words = ["zaaaz"]
17-
* Output: [1]
18-
* Explanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").
19-
*
20-
* Example 2:
21-
* Input: queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]
22-
* Output: [1,2]
23-
* Explanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").
24-
*
25-
* Constraints:
26-
* 1 <= queries.length <= 2000
27-
* 1 <= words.length <= 2000
28-
* 1 <= queries[i].length, words[i].length <= 10
29-
* queries[i][j], words[i][j] are English lowercase letters.
30-
* */
315
publicclass_1170 {
326
publicstaticclassSolution1 {
337
/**
348
* Use simple iteration when finding counts
359
* Time: O(n^m) where m is the size of queries and n is the size of words
3610
* Space: O(max(m, n) where m is the size of queries and n is the size of words)
37-
* */
11+
*/
3812
publicint[]numSmallerByFrequency(String[]queries,String[]words) {
3913
int[]queriesMinFrequecies =newint[queries.length];
4014
for (inti =0;i <queries.length;i++) {
@@ -87,7 +61,7 @@ public static class Solution2 {
8761
* Use binary search when finding counts
8862
* Time: O(n^logn) where m is the size of queries and n is the size of words
8963
* Space: O(max(m, n) where m is the size of queries and n is the size of words)
90-
* */
64+
*/
9165
publicint[]numSmallerByFrequency(String[]queries,String[]words) {
9266
int[]queriesMinFrequecies =newint[queries.length];
9367
for (inti =0;i <queries.length;i++) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp