Skip to content

Instantly share code, notes, and snippets.

@yevmoroz
Created April 16, 2024 13:17
Show Gist options
  • Save yevmoroz/2b8b9612c4e01e7b60c163d0fe67b6d5 to your computer and use it in GitHub Desktop.
Save yevmoroz/2b8b9612c4e01e7b60c163d0fe67b6d5 to your computer and use it in GitHub Desktop.
leetcode uncommon words
function uncommonWords(s1, s2) {
const words1 = s1.split(' ');
const words2 = s2.split(' ');
const freq = new Map();
for (const word of words1) {
freq.set(word, (freq.get(word) || 0) + 1);
}
for (const word of words2) {
freq.set(word, (freq.get(word) || 0) + 1);
}
const result = [];
for (const [word, count] of freq) {
if (count === 1) {
result.push(word);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment