Skip to content

Commit 22328dc

Browse files
author
caiminchao
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # solution.py
2 parents 25fbe5f + 11ad65a commit 22328dc

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

solution.py

+47-7
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ def generateParenthesis(self, n):
397397
:type n: int
398398
:rtype: List[str]
399399
"""
400-
401400
def _dfs(left, right, out, res):
402401
if left < 0 or right < 0 or left > right:
403402
return
@@ -512,9 +511,54 @@ def divide(self, dividend, divisor):
512511
:type divisor: int
513512
:rtype: int
514513
"""
514+
print abs(dividend)
515+
if divisor == -1 and dividend == -2147483648:
516+
return 2147483647
517+
elif divisor == 1:
518+
return dividend
519+
res = 0
520+
dvd = abs(dividend)
521+
dvr = abs(divisor)
522+
while dvd >= dvr:
523+
tmp = dvr
524+
s = 1
525+
while dvd >= (tmp << 1):
526+
tmp = tmp << 1
527+
s <<= 1
528+
529+
dvd = dvd - tmp
530+
res = res + s
531+
532+
if (divisor < 0) ^ (dividend < 0):
533+
return -res
534+
return res
515535

516-
pass
536+
# leetcode30TODO
537+
def findSubstring(self, s, words):
538+
"""
539+
:type s: str
540+
:type words: List[str]
541+
:rtype: List[int]
542+
"""
543+
def _contate_string(str_list, s, s_list):
544+
if len(str_list) == 0:
545+
s_list.append(s)
546+
return
547+
else:
548+
for i in str_list:
549+
tmp = [t for t in str_list]
550+
s += i
551+
tmp.remove(i)
552+
_contate_string(tmp, s, s_list)
553+
554+
s_list = []
555+
_contate_string(words, '', s_list)
556+
res = []
557+
for sl in s_list:
558+
if s.find(sl):
559+
res.append(s.find(sl))
517560

561+
return res
518562
def LCS(self, s1, s2):
519563
"""
520564
计算两个字符串的最长公共子序列.
@@ -584,8 +628,4 @@ def struct_sequence(self, B, i, j, s1, s2):
584628

585629

586630
if __name__ == '__main__':
587-
B, C = Solution().LCS('ABCBDAB', 'BDCABA')
588-
print B
589-
print C
590-
print C[-1, -1]
591-
Solution().struct_sequence(B, B.shape[0] - 1, B.shape[1] - 1, 'ABCBDAB', 'BDCABA')
631+
print Solution().findSubstring('barfoothefoobarman', ["foo", "bar"])

0 commit comments

Comments
 (0)