Leetcode747.Largest Number At Least Twice of Others至少是其他数字两倍的最大数
在一个给定的数组nums中,总是存在一个最大元素 。
查找数组中的最大元素是否至少是数组中每个其他数字的两倍。
如果是,则返回最大元素的索引,否则返回-1。
示例 1:
输入: nums = [3, 6, 1, 0] 输出: 1 解释: 6是最大的整数, 对于数组中的其他整数, 6大于数组中其他元素的两倍。6的索引是1, 所以我们返回1.
示例 2:
输入: nums = [1, 2, 3, 4] 输出: -1 解释: 4没有超过3的两倍大, 所以我们返回 -1.
提示:
- nums 的长度范围在[1, 50].
- 每个 nums[i] 的整数范围在 [0, 99].
class Solution {
public:
int dominantIndex(vector<int>& nums) {
int MAX = -1;
int res = -1;
int len = nums.size();
for(int i = 0; i < len; i++)
{
if(nums[i] > MAX)
{
MAX = nums[i];
res = i;
}
}
for(int i = 0; i < len; i++)
{
if(res != i && MAX < 2 * nums[i])
return -1;
}
return res;
}
};
Leetcode747.Largest Number At Least Twice of Others至少是其他数字两倍的最大数的更多相关文章
- [LeetCode] Largest Number At Least Twice of Others 至少是其他数字两倍的最大数
In a given integer array nums, there is always exactly one largest element. Find whether the largest ...
- Leetcode747至少是其他数字两倍的最大数
Leetcode747至少是其他数字两倍的最大数 在一个给定的数组nums中,总是存在一个最大元素 .查找数组中的最大元素是否至少是数组中每个其他数字的两倍.如果是,则返回最大元素的索引,否则返回-1 ...
- [Swift]LeetCode747. 至少是其他数字两倍的最大数 | Largest Number At Least Twice of Others
In a given integer array nums, there is always exactly one largest element. Find whether the largest ...
- [LC]747题 Largest Number At Least Twice of Others (至少是其他数字两倍的最大数)
①中文题目 在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 1: 输入: nums ...
- LeetCode747 至少是其他数字两倍的最大数
在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 1: 输入: nums = [3, ...
- C#LeetCode刷题之#747-至少是其他数字两倍的最大数( Largest Number At Least Twice of Others)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3746 访问. 在一个给定的数组nums中,总是存在一个最大元素 ...
- 747. Largest Number At Least Twice of Others比所有数字都大两倍的最大数
[抄题]: In a given integer array nums, there is always exactly one largest element. Find whether the l ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- [LeetCode] Largest Number 最大组合数
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
随机推荐
- Python的几个高级编程技巧
Python有一些技巧对你来说是新知识,但是还有一些技巧会让你的代码效率大幅提升. 本文总结了一下自己用到的一些Python高级编程技巧,希望对大家有帮助. 列表生成器 a=[1,2,3] [x*x ...
- mysql中not in子查询不能为空
转载自:https://blog.csdn.net/headingalong/article/details/77744755 错误sql delete from company_info where ...
- c++ 链接mysql:error LNK2019: 无法解析的外部符号
使用VS2012编译项目报错如下: error LNK2019: 无法解析的外部符号 _mysql_real_connect@32,该符号在函数 _main 中被引用 error LNK2019: 无 ...
- maximum clique 1
maximum clique 1 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288KSpecial Judge, 64bit IO Format: % ...
- Django项目:CRM(客户关系管理系统)--47--38PerfectCRM实现全局账号登录注销02
图片另存为 16*16 名字修改为 global_logo.jpg /*! *bootstrap.js * * Bootstrap v3.3.7 (http://getbootstrap ...
- TZ_05_Spring_转账事务基于xml的开发
事务:通过接口的动态代理加强AccountService 实现转账的事务 ApplicationContext.xml <?xml version="1.0" encodin ...
- JavaScript创建对象的几种方式总结
ECMA把对象定义为:无序属性的集合,其属性可以包含基本值.对象或者函数. 1. 使用Object构造函数创建对象 创建自定义对象的最简单的方式就是创建一个Object的实例,然后再为它添加属性和方法 ...
- shell总结:读取文件、参数、if、分割字符串、数组长度、空文件、变量赋值、多进程、按行切割文件、查看线程
Reference: http://saiyaren.iteye.com/blog/1943207 1. Shell 读取文件和写文件 for line in $(<top30000. ...
- ArrayList,LinkedList,Vestor
Collection是最基本的集合接口,声明了适用于JAVA集合的通用方法,list和set都继承自collection接口. Collection接口的方法 boolean add(Object o ...
- RHEL7系统安装方式
RHEL7系统安装方式包括: 1. 手动安装(介质在本地): 此种方式你可以通过图形界面操作定制你所需安装系统的配置及所需软件包等 优点:直观 缺点:效率低下,配置的东西多时易犯错 此种方式仅适用于初 ...