import java.util.*; public class Gloves { public int findMinimum(int n, int[] left, int[] right) { int ret = 0; for (int i = 0; i < left.length; i++) { if (left[i] == 0) { //处理异常情况 ret += right[i]; right[i] = 0; } if (right[i] == 0) { ret += left[i]; left[i] = 0; } } int leftMin = Arrays.stream(left).filter(num -> num != 0) .min().orElse(0);//找不到最小值返回0 int rightMin = Arrays.stream(right).filter(num -> num != 0) .min().orElse(0); int leftSum = Arrays.stream(left).sum(); int rightSum = Arrays.stream(right).sum(); if (leftSum < rightSum) { return leftSum - leftMin + 2 + ret; } else { return rightSum - rightMin + 2 + ret; } } } 主要分为异常情况和非异常情况,也就是含有0 和 不含有0 , 含有0 我就吧对面的数加在ret上面也置换成0,然后就可转换成非异常情况, 然后求最小值的时候一定要忽略0,一定一定一定!!!!!