Skip to content

Commit 36f3cfd

Browse files
author
caiminchao
committed
Merge remote-tracking branch 'origin/master'
2 parents f943327 + 5c42326 commit 36f3cfd

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

solution.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def letterCombinations(self, digits):
320320
:rtype: List[str]
321321
dfs实践
322322
"""
323+
323324
def _dfs(num, string, res):
324325
if num == length:
325326
res.append(string)
@@ -396,6 +397,7 @@ def generateParenthesis(self, n):
396397
:type n: int
397398
:rtype: List[str]
398399
"""
400+
399401
def _dfs(left, right, out, res):
400402
if left < 0 or right < 0 or left > right:
401403
return
@@ -554,12 +556,11 @@ def findSubstring(self, s, words):
554556
else:
555557
tmp[w] += 1
556558

557-
558-
for i in range(sLen-wordsLen*wordLen+1):
559+
for i in range(sLen - wordsLen * wordLen + 1):
559560
current = {}
560561
j = 0
561562
while j <= wordsLen:
562-
word = s[i+j*wordLen:i+j*wordLen+wordLen]
563+
word = s[i + j * wordLen:i + j * wordLen + wordLen]
563564
if word not in words:
564565
break
565566
if word not in current:
@@ -633,8 +634,26 @@ def struct_sequence(self, B, i, j, s1, s2):
633634
elif B[i, j] == 0:
634635
self.struct_sequence(B, i - 1, j, s1, s2)
635636

637+
# ex.递归求解字符串的子串
638+
def getSubset(self, arr, start, end, b):
639+
s=''
640+
if start == end:
641+
for i in range(len(b)):
642+
if b[i]:
643+
s += arr[i]
644+
print s
645+
print ' '
646+
return
647+
else:
648+
b[start] = False
649+
self.getSubset(arr, start + 1, end, b)
650+
b[start] = True
651+
self.getSubset(arr, start + 1, end, b)
652+
636653

637654
if __name__ == '__main__':
638-
s = "barfoothefoobarman"
639-
words = ["foo", "bar"]
640-
print Solution().findSubstring(s, words)
655+
from collections import defaultdict
656+
d = defaultdict(list)
657+
for k,v in {'cai':['li','mc'], 'min':'zi', 'chao':'pei'}.items():
658+
d[k].append(v)
659+
print d

0 commit comments

Comments
 (0)