# 2100. Find Good Days to Rob the Bank ###### tags: `Leetcode` `Medium` `Dynamic Programming` Link: https://leetcode.com/problems/find-good-days-to-rob-the-bank/description/ ## 思路 基本型I prefix[i]表示以security[i]结尾的最长的decreasing序列 suffix[i]表示以security[i]开始的最长的increasing序列 ## Code ```java= class Solution { public List<Integer> goodDaysToRobBank(int[] security, int time) { int n = security.length; int[] prefix = new int[n]; int[] suffix = new int[n]; for(int i=0; i<n; i++){ if(i==0 || security[i-1]<security[i]) prefix[i] = 0; else prefix[i] = prefix[i-1]+1; } for(int i=n-1; i>=0; i--){ if(i==n-1 || security[i+1]<security[i]) suffix[i] = 0; else suffix[i] = suffix[i+1]+1; } List<Integer> ans = new ArrayList<>(); for(int i=0; i<n; i++){ if(prefix[i]>=time && suffix[i]>=time) ans.add(i); } return ans; } } ```