取交集的时候用的是set&set不然速度真的过不了有一个10000长度的测试用例
class Solution(object):
def goodDaysToRobBank(self, security, time):
"""
:type security: List[int]
:type time: int
:rtype: List[int]
单调栈啊
双指针吧,递减的话就右指针动,碰到合适的,加入答案
递增左指针等于右指针
"""
len_s=len(security)
def Search_sec(step,l,r):
set_a=set()
while 0<=r<len_s:
if security[r]<=security[r-step]:
if (r-l)*step>=time:
set_a.add(r)
else:
l=r
r=r+step
return set_a
if time==0:return range(len_s)
return list(Search_sec(-1,len_s-1,len_s-2)&Search_sec(1,0,1))