Skip to content

Commit 15c272d

Browse files
committed
0916
1 parent 3f00c9c commit 15c272d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

0901-1000/0916_word_subsets.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# @param {String[]} words1
2+
# @param {String[]} words2
3+
# @return {String[]}
4+
def word_subsets(words1, words2)
5+
words2_max_freq = Hash.new(0)
6+
words2.each { |word|
7+
word.chars.tally.each { |c, count|
8+
words2_max_freq[c] = [words2_max_freq[c], count].max
9+
}
10+
}
11+
12+
words1.select { |word|
13+
word1_freq = word.chars.tally
14+
words2_max_freq.all? { |c, max_count|
15+
word1_freq.has_key?(c) && word1_freq[c] >= max_count
16+
}
17+
}
18+
end

0 commit comments

Comments
 (0)