Skip to content

Commit 5fa4e3b

Browse files
committed
Add solution #916
1 parent 2d5fa29 commit 5fa4e3b

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,51 @@
22

33
[https://leetcode.com/](https://leetcode.com/)
44

5+
## Table of Contents:
6+
7+
|#|Title|Difficulty|
8+
|:---|:---|:---|
9+
36|[Valid Sudoku](./0036-valid-sudoku.js)|Medium|
10+
58|[Length of Last Word](./0058-length-of-last-word.js)|Easy|
11+
151|[Reverse Words in a String](./0151-reverse-words-in-a-string.js)|Medium|
12+
226|[Invert Binary Tree](./0226-invert-binary-tree.js)|Easy|
13+
263|[Ugly Number](./0263-ugly-number.js)|Easy|
14+
264|[Ugly Number II](./0264-ugly-number-ii.js)|Medium|
15+
387|[First Unique Character in a String](./0387-first-unique-character-in-a-string.js)|Easy|
16+
451|[Sort Characters By Frequency](./0451-sort-characters-by-frequency.js)|Medium|
17+
606|[Construct String from Binary Tree](./0606-construct-string-from-binary-tree.js)|Easy|
18+
617|[Merge Two Binary Trees](./0617-merge-two-binary-trees.js)|Easy|
19+
739|[Daily Temperatures](./0739-daily-temperatures.js)|Medium|
20+
791|[Custom Sort String](./0791-custom-sort-string.js)|Medium|
21+
804|[Unique Morse Code Words](./0804-unique-morse-code-words.js)|Easy|
22+
819|[Most Common Word](./0819-most-common-word.js)|Easy|
23+
890|[Find and Replace Pattern](./0890-find-and-replace-pattern.js)|Medium|
24+
916|[Word Subsets](./0916-word-subsets.js)|Medium|
25+
929|[Unique Email Addresses](./0929-unique-email-addresses.js)|Easy|
26+
970|[Powerful Integers](./0970-powerful-integers.js)|Easy|
27+
976|[Largest Perimeter Triangle](./0976-largest-perimeter-triangle.js)|Easy|
28+
977|[Squares of a Sorted Array](./0977-squares-of-a-sorted-array.js)|Easy|
29+
985|[Sum of Even Numbers After Queries](./0985-sum-of-even-numbers-after-queries.js)|Easy|
30+
989|[Add to Array-Form of Integer](./0989-add-to-array-form-of-integer.js)|Easy|
31+
1009|[Complement of Base 10 Integer](./1009-complement-of-base-10-integer.js)|Easy|
32+
1037|[Valid Boomerang](./1037-valid-boomerang.js)|Easy|
33+
1103|[Distribute Candies to People](./1103-distribute-candies-to-people.js)|Easy|
34+
1108|[Defanging an IP Address](./1108-defanging-an-ip-address.js)|Easy|
35+
1189|[Maximum Number of Balloons](./1189-maximum-number-of-balloons.js)|Easy|
36+
1207|[Unique Number of Occurrences](./1207-unique-number-of-occurrences.js)|Easy|
37+
1232|[Check If It Is a Straight Line](./1232-check-if-it-is-a-straight-line.js)|Easy|
38+
1252|[Cells with Odd Values in a Matrix](./1252-cells-with-odd-values-in-a-matrix.js)|Easy|
39+
1287|[Element Appearing More Than 25% In Sorted Array](./1287-element-appearing-more-than-25-in-sorted-array.js)|Easy|
40+
1290|[Convert Binary Number in a Linked List to Integer](./1290-convert-binary-number-in-a-linked-list-to-integer.js)|Easy|
41+
1291|[Sequential Digits](./1291-sequential-digits.js)|Medium|
42+
1292|[Maximum Side Length of a Square with Sum Less than or Equal to Threshold](./1292-maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold.js)|Medium|
43+
1297|[Maximum Number of Occurrences of a Substring](./1297-maximum-number-of-occurrences-of-a-substring.js)|Medium|
44+
1304|[Find N Unique Integers Sum up to Zero](./1304-find-n-unique-integers-sum-up-to-zero.js)|Easy|
45+
1309|[Decrypt String from Alphabet to Integer Mapping](./1309-decrypt-string-from-alphabet-to-integer-mapping.js)|Easy|
46+
1313|[Decompress Run-Length Encoded List](./1313-decompress-run-length-encoded-list.js)|Easy|
47+
1317|[Convert Integer to the Sum of Two No-Zero Integers](./1317-convert-integer-to-the-sum-of-two-no-zero-integers.js)|Easy|
48+
1318|[Minimum Flips to Make a OR b Equal to c](./1318-minimum-flips-to-make-a-or-b-equal-to-c.js)|Medium|
49+
550
## License
651

752
[MIT License](https://opensource.org/licenses/MIT)

solutions/0916-word-subsets.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 916. Word Subsets
3+
* https://leetcode.com/problems/word-subsets/
4+
* Difficulty: Medium
5+
*
6+
* We are given two arrays A and B of words. Each word is a string of lowercase letters.
7+
*
8+
* Now, say that word b is a subset of word a if every letter in b occurs in a, including
9+
* multiplicity. For example, "wrr" is a subset of "warrior", but is not a subset of "world".
10+
*
11+
* Now say a word a from A is universal if for every b in B, b is a subset of a.
12+
*
13+
* Return a list of all universal words in A. You can return the words in any order.
14+
*/
15+
16+
/**
17+
* @param {string[]} A
18+
* @param {string[]} B
19+
* @return {string[]}
20+
*/
21+
var wordSubsets = function(A, B) {
22+
const count = (string, char) => string.split(char).length - 1;
23+
const subset = Array.from(B.reduce((map, b) => {
24+
b.split('').forEach(char => {
25+
map.set(char, (map.get(char) || 0) > count(b, char) ? map.get(char) : count(b, char));
26+
});
27+
return map;
28+
}, new Map()));
29+
return A.filter(a => subset.every(match => count(a, match[0]) >= match[1]));
30+
};

0 commit comments

Comments
 (0)