-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path1079.LetterTilePossibilities.py
42 lines (34 loc) · 1.09 KB
/
1079.LetterTilePossibilities.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
'''
You have n 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 using the letters printed on those
tiles.
Example:
Input: tiles = "AAB"
Output: 8
Explanation: The possible sequences are "A", "B", "AA",
"AB", "BA", "AAB", "ABA", "BAA".
Example:
Input: tiles = "AAABBC"
Output: 188
Example:
Input: tiles = "V"
Output: 1
Constraints:
- 1 <= tiles.length <= 7
- tiles consists of uppercase English letters.
'''
#Difficulty: Medium
#86 / 86 test cases passed.
#Runtime: 80 ms
#Memory Usage: 15.3 MB
#Runtime: 80 ms, faster than 63.69% of Python3 online submissions for Letter Tile Possibilities.
#Memory Usage: 15.3 MB, less than 57.87% of Python3 online submissions for Letter Tile Possibilities.
from itertools import permutations
class Solution:
def numTilePossibilities(self, tiles: str) -> int:
n = 0
for i in range(1, len(tiles)+1):
n += len(set(permutations(tiles, i)))
return n