编程小技巧
技巧 - stream 找最大值
https://leetcode.cn/problems/all-divisions-with-the-highest-score-of-a-binary-array/description/
public class test {public static void main(String[] args) {int[] num = new int[]{0, 0, 1, 0};maxScoreIndices(num);}public static List<Integer> maxScoreIndices(int[] nums) {int left = 0, rigth = Arrays.stream(nums).sum();int length = nums.length;int[] temp = new int[length + 1];temp[0] = rigth;int i = 1;for (; i < length; i++) {if (nums[i - 1] == 0) {left++;} else {rigth--;}temp[i] = left + rigth;}if (nums[i - 1] == 0)left++;temp[i] = left;List<Integer> ans = new ArrayList<>();OptionalInt max = Arrays.stream(temp).max();for (i = 0; i < length + 1; i++) {if (OptionalInt.of(temp[i]).equals(max)) {System.out.println(i);ans.add(i);}}return ans;}
}