【发布时间】:2018-01-25 23:04:41
【问题描述】:
有没有一种有效的方法来返回数组位置,其中给定位置的值大于阈值并且后续位置小于该阈值?我可以在一个循环中完成此操作,但对于具有 100,000 多个条目的数组来说非常慢。
举个例子,
x=[4,9,1,5,7,8,10,11,2,4]
threshold=3
# find elements greater than 3 and where the next element is less than 3
return [1,7] #corresponding to indexes for values 9 and 11 in x
【问题讨论】: