# LeetCode - 0747. Largest Number At Least Twice of Others
### 題目網址:https://leetcode.com/problems/largest-number-at-least-twice-of-others/
###### tags: `LeetCode` `Easy`
```cpp=
/*
-LeetCode format-
Problem: 747. Largest Number At Least Twice of Others
Difficulty: Easy
by Inversionpeter
*/
class Solution {
public:
int dominantIndex(vector<int>& nums) {
int first = nums[0], second = -1, firstAt = 0;
for (int i = 1; i != nums.size(); ++i) {
if (first == nums[i] || second == nums[i])
continue;
if (first < nums[i])
second = first, first = nums[i], firstAt = i;
else if (second < nums[i])
second = nums[i];
}
return (second == -1 || first >= (second << 1) ? firstAt : -1);
}
};
```