题解 | #动物牛的最小和#
动物牛的最小和
https://www.nowcoder.com/practice/8aa4227c02aa4d989f31f2beea4f3536
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param k int整型 * @return int整型 */ public int findMinSum (int[] nums, int k) { // write code here int n = nums.length; int min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (nums[i] + nums[j] > k) { if (min > nums[i] + nums[j]) { min = nums[i] + nums[j]; } } } } return min == Integer.MAX_VALUE ? -1 : min ; } }