Count Words Obtained After Adding a Letter LeetCode solution in JavaScript

1
var wordCount = function (startWords, targetWords) {
2
const startMap = {};
3
for (let word of startWords) {
4
startMap[word.split("").sort().join("")] = true;
5
}
6

7
let ans = 0;
8
for (let word of targetWords) {
9
for (let i = 0; i < word.length; i++) {
10
let temp = (word.substring(0, i) + word.substring(i + 1, word.length))
11
.split("")
12
.sort()
13
.join("");
14
if (startMap[temp]) {
15
ans++;
16
break;
17
}
18
}
19
}
20

21
return ans;
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0