Skip to content

Commit 2eb4fc4

Browse files
authored
Update naming-a-company.cpp
1 parent 3010036 commit 2eb4fc4

File tree

1 file changed

+0
-31
lines changed

1 file changed

+0
-31
lines changed

C++/naming-a-company.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,3 @@ class Solution {
2222
return result * 2;
2323
}
2424
};
25-
26-
// Time: O(26 * n * l)
27-
// Space: O(n * l)
28-
// hash table, math
29-
class Solution2 {
30-
public:
31-
long long distinctNames(vector<string>& ideas) {
32-
vector<unordered_set<string>> lookup(26);
33-
for (const auto& idea : ideas) {
34-
lookup[idea[0] - 'a'].emplace(idea.substr(1));
35-
}
36-
vector<vector<int64_t>> cnt(26, vector<int64_t>(26));
37-
for (int i = 0; i < 26; ++i) {
38-
for (const auto& x : lookup[i]) {
39-
for (int j = 0; j < 26; ++j) {
40-
if (j == i) {
41-
continue;
42-
}
43-
cnt[i][j] += !lookup[j].count(x);
44-
}
45-
}
46-
}
47-
int64_t result = 0;
48-
for (int i = 0; i < 26; ++i) {
49-
for (int j = i + 1; j < 26; ++j) {
50-
result += cnt[i][j] * cnt[j][i];
51-
}
52-
}
53-
return result * 2;
54-
}
55-
};

0 commit comments

Comments
 (0)