class Solution {
public:
int dominantIndex(vector<int>& nums) {
int max = 0, tmp = 0,index = 0;
for (int i = 0; i<nums.size(); i++) {
if(nums[i]>=max) {
tmp = max;
max = nums[i];
index = i;
}else if (nums[i]>tmp){
tmp = nums[i];
}
if (i==nums.size()-1 && tmp*2<=max) return index;
}
return -1;
}
};
Largest Number At Least Twice of Others
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.