【java】747. Largest Number At Least Twice of Others

xiaoxiao2021-02-28  32

问题原文点击打开链接

这道题简单的不用思考.....

public int dominantIndex(int[] nums) { int maxVal = Integer.MIN_VALUE; int pos = 0; for (int i = 0;i<nums.length;i++){ if (nums[i] > maxVal){ pos = i; maxVal = nums[i]; } } for (int i = 0;i<nums.length;i++){ if (maxVal < 2*nums[i] && i != pos) return -1; } return pos; }
转载请注明原文地址: https://www.6miu.com/read-2623235.html

最新回复(0)