WePay.md 1.2 KB
Newer Older
K
KEQI HUANG 已提交
1
如图,![](https://github.com/Lisanaaa/thinking_in_lc/blob/master/interview%20question/WePay/WePay.jpg)
K
KEQI HUANG 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

就是一个slide windows 的题目

```python
inputs = [5,1,2,100,2,2]
def alert(inputs, windowSize, allowedIncrease):
    b = []
    tmp = {}
    for i in range(len(inputs) - windowSize):
        for j in range(i, i+windowSize+1):
            if j in tmp.keys():
                if j > len(inputs) - windowSize-1:
                    tmp.get(j).append(inputs[i+1:i + windowSize+1])
                else:
                    tmp.get(j).append(inputs[i:i+windowSize])
            else:
                print(j,j, i, i+ windowSize)
                if j > len(inputs) - windowSize -1:
                    tmp[j] = [inputs[i+1:i + windowSize+1]]
                else:
                    tmp[j] = [inputs[i:i+windowSize]]
    b = [inputs[i:i+windowSize] for i in range(len(inputs)-windowSize)]
    print(tmp)
    for num in tmp.keys():
        if all(inputs[num] > sum(lis)/windowSize*allowedIncrease for lis in tmp.get(num)):
            return True
    b = [sum(i)/windowSize for i in b]
    for i in range(len(b)):
        if any(b[i] > b[j]*allowedIncrease for j in range(i)):
            return True
    return False
print(alert(inputs,3,1.5))
```