- Notifications
You must be signed in to change notification settings - Fork 625
/
Copy path1079.py
47 lines (38 loc) · 1.23 KB
/
1079.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''
You have a set of tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make.
Example 1:
Input: "AAB"
Output: 8
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".
Example 2:
Input: "AAABBC"
Output: 188
'''
classSolution(object):
defnumTilePossibilities(self, tiles):
"""
:type tiles: str
:rtype: int
"""
ifnottiles:
return0
importcollections
unique=set(tiles)
freq_map=collections.Counter(tiles)
total_len=1
whiletotal_len<len(tiles):
new=set()
forcharintiles:
forcombinunique:
new_seq=comb+char
up_freq=collections.Counter(new_seq)
flag=True
forkey, valinup_freq.items():
ifval>freq_map[key]:
flag=False
ifflag:
new.add(new_seq)
# print new
unique.update(new)
total_len+=1
returnlen(unique)