-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path784.Letter Case Permutation.py
More file actions
39 lines (34 loc) · 1.06 KB
/
784.Letter Case Permutation.py
File metadata and controls
39 lines (34 loc) · 1.06 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
# -*- coding: utf-8 -*-
# @Time : 2019/2/25 11:46
# @Author : xulzee
# @Email : xulzee@163.com
# @File : 784.Letter Case Permutation.py
# @Software: PyCharm
class Solution:
def letterCasePermutation(self, S: 'str') -> 'List[str]':
result = []
if S == "":
return [""]
print(result)
for i in S:
if i.isalpha():
if result == []:
result.append(i.lower())
result.append(i.upper())
else:
temp = []
temp = result[:]
for j in range(len(result)):
result[j] += i.lower()
temp[j] += i.upper()
result = result + temp
else:
if result == []:
result.append(i)
else:
for j in range(len(result)):
result[j] += i
return result
if __name__ == '__main__':
S = "a1b2"
print(Solution().letterCasePermutation(S))