中等题也勉强一试
class Solution {
public List<Integer> maxScoreIndices(int[] nums) {
List<Integer> list = new ArrayList<>();
int n = nums.length;
int[] ans = new int[n + 1];
int c0 = 0;
int c1 = 0;
for(int i = 0; i <n; i++){
if(nums[i] == 1) c1 ++;
}
ans[0] = c1;
int max = ans[0];
for(int i = 0; i < n; i++){
if(nums[i] == 0){
c0++;
ans[i + 1] = c0 + c1;
}else{
c1--;
ans[i + 1] = c0 + c1;
}
max = Math.max(ans[i + 1], max);
}
for(int i = 0; i < n + 1; i++){
if(ans[i] == max) list.add(i);
}
return list;
}
}