LeetCode-748-Largest Number At Least Twice of Others(C语言实现)
2017-12-29 16:28
411 查看
int dominantIndex(int* nums, int numsSize) {
if(numsSize <= 0) return -1;
int max = nums[0];
int smax = 0;
int i;
int flag = 0;
for(i = 1; i < numsSize; ++i){
if(nums[i] <= smax) continue;
if(nums[i] >= max){
smax = max;
max = nums[i];
flag = i;
}
else{
smax = nums[i];
}
}
if(max >= smax * 2) return flag;
else return -1;
}
if(numsSize <= 0) return -1;
int max = nums[0];
int smax = 0;
int i;
int flag = 0;
for(i = 1; i < numsSize; ++i){
if(nums[i] <= smax) continue;
if(nums[i] >= max){
smax = max;
max = nums[i];
flag = i;
}
else{
smax = nums[i];
}
}
if(max >= smax * 2) return flag;
else return -1;
}
相关文章推荐
- [LeetCode] Largest Number At Least Twice of Others 至少是其他数字两倍的最大数
- Largest Number At Least Twice of Others
- Largest Number At Least Twice of Others
- leetcode :Find the contiguous subarray within an array (containing at least one number) which has th
- LeetCode-4-Median of Two Sorted Arrays(C语言实现)
- CareerCup Find the smallest range that includes at least one number from each of the k sorted lists.
- LeetCode-19-Remove Nth Node From End of List(C语言实现)
- 【LeetCode-面试算法经典-Java实现】【200-Number of Islands(岛的数目)】
- 一道题目- Find the smallest range that includes at least one number from each of the k lists
- The maximum number of processes for the user account running is currently , which can cause performance issues. We recommend increasing this to at least 4096.
- max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
- mongodb 安装后 出现警告:** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
- LeetCode[200] Number of Islands
- LeetCode 395 Longest Substring with At Least K Repeating Characters
- [LeetCode42]Letter Combinations of a Phone Number
- LeetCode之Letter Combinations of a Phone Number
- LeetCode Online Judge 题目C# 练习 - Letter Combinations of a Phone Number
- Leetcode 447 Number of Boomerangs
- LeetCode-Number of Connected Components in an Undirected Graph
- LeetCode(17) Letter Combinations of a Phone Number