适合野炊的日子 (Find Good Days to Rob the Bank)

 

思路:

// @Title: 适合野炊的日子 (Find Good Days to Rob the Bank)
// @Author: qisiii
// @Date: 2022-03-08 10:12:52
// @Runtime: 6 ms
// @Memory: 60.5 MB
// @comment: 
// @flag: 
class Solution {
    public List<Integer> goodDaysToRobBank(int[] security, int time) {
        List<Integer> result=new ArrayList();
        int n=security.length;
        int[] left=new int[n];
        int[] right=new int[n];
        for(int i=1;i<n;i++){
            if(security[i]<=security[i-1]){
                left[i]=left[i-1]+1;
            }
            if(security[n-i-1]<=security[n-i]){
                right[n-i-1]=right[n-i]+1;
            }
        }
        for(int i=time;i<n-time;i++){
            if(left[i]>=time&&right[i]>=time){
                result.add(i);
            }
        }
        return result;
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18