-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1079.py
More file actions
51 lines (37 loc) · 1.25 KB
/
1079.py
File metadata and controls
51 lines (37 loc) · 1.25 KB
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
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/5/10 12:39
# @Author : Fhh
# @File : 1079.py
# Good good study,day day up!
"""你有一套活字字模 tiles,其中每个字模上都刻有一个字母 tiles[i]。返回你可以印出的非空字母序列的数目。
注意:本题中,每个活字字模只能使用一次。
示例 1:
输入:"AAB"
输出:8
解释:可能的序列为 "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA"。
示例 2:
输入:"AAABBC"
输出:188
提示:
1 <= tiles.length <= 7
tiles 由大写英文字母组成
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/letter-tile-possibilities
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。"""
class Solution:
def numTilePossibilities(self, tiles: str) -> int:
res = dict()
def save_result(tmp, n, titles):
if tmp:
res[tmp] = 1
if len(tmp) == n:
return
for i in range(len(titles)):
save_result(tmp + titles[i], n, titles[:i] + titles[i + 1:])
save_result('', len(tiles), tiles)
return len(res)
s = Solution()
print(s.numTilePossibilities("AAABBC"))