class Solution(object):
def findLongestWord(self, s, d):
"""
:type s: str
:type d: List[str]
:rtype: str
"""
d.sort(key = lambda x: [-len(x),x]) #按照长度降序,字典升序排列
for c in d:
i = 0
count = 0
for j in c:
k = s.find(j,i)
count += 1
if k == -1:
break
i = k+1
if count == len(c):
return c
return ""
class Solution(object):
def findMaxLength(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
for val in range(len(nums)):
if nums[val] == 0:
nums[val] = -1
res = 0
count = 0
dic = {0:-1}
for i in range(len(nums)):
count += nums[i]
if count in dic:
res = max(res,i-dic[count])
else:
dic[count] = i
return res