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 c0741a9

Browse files
authoredAug 25, 2019
Create 1170-compare-strings-by-frequency-of-the-smallest-character.js
1 parent 799d712 commit c0741a9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @param {string[]} queries
3+
* @param {string[]} words
4+
* @return {number[]}
5+
*/
6+
const numSmallerByFrequency = function(queries, words) {
7+
const qArr = []
8+
for(let i = 0, len = queries.length; i < len; i++) {
9+
let sm = 'z'
10+
let hash = {}
11+
let cur = queries[i]
12+
for(let char of cur) {
13+
if(hash[char] == null) hash[char] = 0
14+
hash[char]++
15+
if(char < sm) sm = char
16+
}
17+
qArr.push(hash[sm])
18+
}
19+
const wArr = []
20+
for(let i = 0, len = words.length; i < len; i++) {
21+
let sm = 'z'
22+
let hash = {}
23+
let cur = words[i]
24+
for(let char of cur) {
25+
if(hash[char] == null) hash[char] = 0
26+
hash[char]++
27+
if(char < sm) sm = char
28+
}
29+
wArr.push(hash[sm])
30+
}
31+
const res = []
32+
for(let i = 0, len = queries.length; i < len; i++) {
33+
let cur = 0
34+
for(let j = 0, wlen = words.length; j < wlen; j++) {
35+
if(qArr[i] < wArr[j]) cur++
36+
}
37+
res.push(cur)
38+
}
39+
return res
40+
};

0 commit comments

Comments
 (0)
Please sign in to comment.