jianglilili / jianglilili/Lintcode-
至少是其他数字两倍的最大值(Largest Number At Least Twice of Others)
Open
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
以此纪念我刷题一个多月以来,不看题解,自己做的,而且运行成功的第一道题
**解题思路**:先求出数组的最大值,再比较数组中小于最大值m的数,如果数组中的某个数的两倍比最大值m大,那么就返回-1,函数运行到此结束,如果数字的两倍没有比m大的,那么就找出与m相等的那个数,返回i
```
public class Solution {
/**
* @param nums: a integer array
* @return: the index of the largest element
*/
public int dominantIndex(int[] nums) {
// Write your code here
int ans=0;
int m=maxNum(nums);
for(int i=0;inum)
{
num=nums[i];
}
}
return num;
}
}
```
求最大值的方法有点笨,肯定还有更简便的方法(继续学习,加油!)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.