747. Largest Number At Least Twice of Others
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int dominantIndex(vector<int>& nums)
{
int firstmax=INT_MIN,secondmax=INT_MIN,index=-;
int sz=nums.size();
for(int i=;i<sz;i++)
{
if(nums[i]>firstmax)
{
secondmax=firstmax;
firstmax=nums[i];
index=i;
}
else if(nums[i]>secondmax)
secondmax=nums[i];
}
return (firstmax>=*secondmax)? index:-;
}
};
扫描一遍,找出最大和第二大的就行了
747. Largest Number At Least Twice of Others的更多相关文章
- 【Leetcode_easy】747. Largest Number At Least Twice of Others
problem 747. Largest Number At Least Twice of Others 题意: solution1: class Solution { public: int dom ...
- [LeetCode] 747. Largest Number At Least Twice of Others_Easy
In a given integer array nums, there is always exactly one largest element. Find whether the largest ...
- 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 ...
- leetcode 747. Largest Number At Least Twice of Others
In a given integer array nums, there is always exactly one largest element. Find whether the largest ...
- 【LeetCode】747. Largest Number At Least Twice of Others 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 寻找两次最大值 排序 大顶堆 日期 题目地址:htt ...
- 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 ...
- 【leetcode】Largest Number
题目简述: Given a list of non negative integers, arrange them such that they form the largest number. Fo ...
- leetcode 179. Largest Number 求最大组合数 ---------- java
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
随机推荐
- Shell教程 之运算符
1.Shell基本运算符 Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符: 关系运算符: 布尔运算符: 字符串运算符: 文件测试运算符. 原生bash不支持简单的数学运算,但是可以 ...
- if (HttpContext.Current.User.Identity.IsAuthenticated) 权限验证总是true
将浏览器关闭重启. 注:该语句是判断用户是否经过验证.
- RxJS之转化操作符 ( Angular环境 )
一 map操作符 类似于大家所熟知的 Array.prototype.map 方法,此操作符将投射函数应用于每个值 并且在输出 Observable 中发出投射后的结果. import { Compo ...
- [剑指Offer]53-在排序数组中查找数字(二分查找)
题目一 数字在排序数组中出现的个数 题目描述 统计一个数字在排序数组中出现的次数. 解决思路 写两个二分查找分别找第一个和最后一个该数字,然后可直接出计算有几个该数字.时间复杂度为O(logn). 这 ...
- Javascript(es2016) import和require用法和区别
http://blog.csdn.net/chinaycheng/article/details/52559439 其中这个总结很到位: 加载方式 规范 命令 特点 运行时加载 CommonJS/AM ...
- django static 无法正确加载目录下的css
在static->web目录下添加CSS后该css文件一直报404错误,解决问题: 在setting.py文件添加: STATICFILES_DIRS = [ os.path.join(BASE ...
- sqlserver编号
select ROW_NUMBER() OVER (ORDER BY 字段 DESC) AS rid,* from 表名
- Volley超时重试机制
基础用法 Volley为开发者提供了可配置的超时重试机制,我们在使用时只需要为我们的Request设置自定义的RetryPolicy即可. 参考设置代码如下: int DEFAULT_TIMEOUT_ ...
- shell脚本实例总结
1.判断文件夹是否存在 #!/bin/sh workspace="/home/web/mall" #如果文件夹不存在 if [ ! -d ${workspace} ]; then ...
- (二)创建ROS工作空间
ROS 教程中涉及的和编写的所有 ROS 代码需要有一个地方存放它,这个地方叫做工作空间.可以说,这个工作空间应该是一个大的集合.当我们要编译程序的时候,我们是对整个工作空间进行编译的. 这个工作空 ...