Skip to content

Commit fd64d2a

Browse files
committed
Add solution #884
1 parent ca7155d commit fd64d2a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
831|[Masking Personal Information](./0831-masking-personal-information.js)|Medium|
5757
844|[Backspace String Compare](./0844-backspace-string-compare.js)|Easy|
5858
867|[Transpose Matrix](./0867-transpose-matrix.js)|Easy|
59+
884|[Uncommon Words from Two Sentences](./0884-uncommon-words-from-two-sentences.js)|Easy|
5960
890|[Find and Replace Pattern](./0890-find-and-replace-pattern.js)|Medium|
6061
916|[Word Subsets](./0916-word-subsets.js)|Medium|
6162
925|[Long Pressed Name](./0925-long-pressed-name.js)|Easy|
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 884. Uncommon Words from Two Sentences
3+
* https://leetcode.com/problems/uncommon-words-from-two-sentences/submissions/
4+
* Difficulty: Easy
5+
*
6+
* A sentence is a string of single-space separated words where each word consists
7+
* only of lowercase letters.
8+
*
9+
* A word is uncommon if it appears exactly once in one of the sentences, and does
10+
* not appear in the other sentence.
11+
*
12+
* Given two sentences s1 and s2, return a list of all the uncommon words. You may
13+
* return the answer in any order.
14+
*/
15+
16+
/**
17+
* @param {string} s1
18+
* @param {string} s2
19+
* @return {string[]}
20+
*/
21+
var uncommonFromSentences = function(s1, s2) {
22+
const map = new Map();
23+
24+
(s1 + ' ' + s2).split(/\s+/).forEach(s => map.set(s, (map.get(s) || 0) + 1));
25+
return [...map].reduce((a, [k, c]) => c === 1 ? [...a, k] : a, []);
26+
};

0 commit comments

Comments
 (0)