File tree 1 file changed +0
-31
lines changed 1 file changed +0
-31
lines changed Original file line number Diff line number Diff line change @@ -22,34 +22,3 @@ class Solution {
22
22
return result * 2 ;
23
23
}
24
24
};
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
- };
You can’t perform that action at this time.
0 commit comments