#力扣 LeetCode747. 至少是其他數字兩倍的最大數 @FDDLC
阿新 • 來源:網路 • 發佈:2021-02-16
技術標籤:演算法&資料結構
題目描述:
https://leetcode-cn.com/problems/largest-number-at-least-twice-of-others/
Java程式碼:
class Solution {
public int dominantIndex(int[] a) {
int ans=0;
for(int i=1;i<a.length;i++)if(a[ans]<a[i])ans=i;
for(int e:a)if(a[ans]!=e&&a[ans]<e+e)return -1;
return ans;
}
}

