lc6190找到所有好下标
class Solution {
public List<Integer> goodIndices(int[] nums, int k) {
int[] left = new int[nums.length], right = new int[nums.length];
for (int i = 2; i < nums.length; i++) {
left[i] = nums[i - 1] > nums[i - 2] ? 0 : left[i - 1] + 1;
}
for (int i = nums.length - 3; i >= 0; i--) {
right[i] = nums[i + 1] > nums[i + 2] ? 0 : right[i + 1] + 1;
}
List<Integer> list = new ArrayList<>();
for (int i = 1; i < nums.length - 1; ++i) {
if (left[i] >= k - 1 && right[i] >= k - 1) {
list.add(i);
}
}
return list;
}
}
预处理前缀-> 收集结果
标签:week,right,lc,nums,后缀,int,length,new,left From: https://www.cnblogs.com/beichuang/p/16728156.html