Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 835a663

Browse files
committedAug 12, 2020
refactor 1170
1 parent 5021334 commit 835a663

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
import java.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
public class _1170 {
326
public static class Solution1 {
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
public int[] numSmallerByFrequency(String[] queries, String[] words) {
3913
int[] queriesMinFrequecies = new int[queries.length];
4014
for (int i = 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
public int[] numSmallerByFrequency(String[] queries, String[] words) {
9266
int[] queriesMinFrequecies = new int[queries.length];
9367
for (int i = 0; i < queries.length; i++) {

0 commit comments

Comments
 (0)
Failed to load comments.