We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2eb4fc4 commit a34b919Copy full SHA for a34b919
Python/naming-a-company.py
@@ -17,29 +17,3 @@ def distinctNames(self, ideas):
17
common = len(lookup[i]&lookup[j])
18
result += (len(lookup[i])-common)*(len(lookup[j])-common)
19
return result*2
20
-
21
22
-# Time: O(26 * n * l)
23
-# Space: O(n * l)
24
-# hash table, math
25
-class Solution2(object):
26
- def distinctNames(self, ideas):
27
- """
28
- :type ideas: List[str]
29
- :rtype: int
30
31
- lookup = [set() for _ in xrange(26)]
32
- for x in ideas:
33
- lookup[ord(x[0])-ord('a')].add(x[1:])
34
- cnt = [[0]*26 for _ in xrange(26)]
35
- for i in xrange(26):
36
- for x in lookup[i]:
37
- for j in xrange(26):
38
- if j == i:
39
- continue
40
- cnt[i][j] += x not in lookup[j]
41
- result = 0
42
- for i in xrange(len(lookup)):
43
- for j in xrange(i+1, len(lookup)):
44
- result += cnt[i][j]*cnt[j][i]
45
- return result*2
0 commit comments