@@ -397,7 +397,6 @@ def generateParenthesis(self, n):
397
397
:type n: int
398
398
:rtype: List[str]
399
399
"""
400
-
401
400
def _dfs (left , right , out , res ):
402
401
if left < 0 or right < 0 or left > right :
403
402
return
@@ -512,9 +511,54 @@ def divide(self, dividend, divisor):
512
511
:type divisor: int
513
512
:rtype: int
514
513
"""
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
515
535
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 ))
517
560
561
+ return res
518
562
def LCS (self , s1 , s2 ):
519
563
"""
520
564
计算两个字符串的最长公共子序列.
@@ -584,8 +628,4 @@ def struct_sequence(self, B, i, j, s1, s2):
584
628
585
629
586
630
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