Skip to content

Commit a34b919

Browse files
authored
Update naming-a-company.py
1 parent 2eb4fc4 commit a34b919

File tree

1 file changed

+0
-26
lines changed

1 file changed

+0
-26
lines changed

Python/naming-a-company.py

-26
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,3 @@ def distinctNames(self, ideas):
1717
common = len(lookup[i]&lookup[j])
1818
result += (len(lookup[i])-common)*(len(lookup[j])-common)
1919
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

Comments
 (0)