Skip to content

Commit 1e122fc

Browse files
authored
Create 2306-naming-a-company.js
1 parent 2c1121c commit 1e122fc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2306-naming-a-company.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string[]} ideas
3+
* @return {number}
4+
*/
5+
const distinctNames = function (ideas) {
6+
let smap = Array.from({ length: 26 }, (_) => new Set()),
7+
ans = 0
8+
for (let i = 0; i < ideas.length; i++) {
9+
let word = ideas[i]
10+
smap[word.charCodeAt(0) - 97].add(word.slice(1))
11+
}
12+
for (let i = 0; i < 25; i++) {
13+
let a = smap[i]
14+
for (let j = i + 1; j < 26; j++) {
15+
let b = smap[j],
16+
count = 0
17+
for (let w of a) if (b.has(w)) count++
18+
ans += (a.size - count) * (b.size - count) * 2
19+
}
20+
}
21+
return ans
22+
}

0 commit comments

Comments
 (0)