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 ...
随机推荐
- Mybatis抛出 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@f54509]异常
今天在做Springmvc和spring 时 mybatis 是抛出异常 Closing non transactional SqlSession [org.apache.ibatis.session ...
- oracle 中从某天到某天一天一次执行某个函数
DECLAREv_days INTEGER;v_start VARCHAR2(10);v_end VARCHAR2(10);v_3 INTEGER;v_enddays date;begin v_sta ...
- oracle中的to_number在mysql中的转换
select cast(11 as unsigned int) /*整型*/ select cast(11 as decimal(10,2)) /*浮点型*/ 注:(10,2)代表数字共十位,小数点后 ...
- 微信公众号开发(5)---使用开源组件开发公众号OAuth2.0网页授权授权登录
搞清微信公众号授权登录的步骤步骤,我们的开发就完成了一大步 献上github 地址: https://github.com/Wechat-Group/weixin-java-tools/wiki/MP ...
- Java05-Java基础语法(四)循环结构
Java05-Java基础语法(四)循环结构 循环结构(重复/迭代):根据条件重复执行部分语句 1.while循环结构 while(条件表达式){ 循环体语句; } 1)语法:a.while是关键字 ...
- BitCoinCore配置文件解读
bitcoin.conf 配置文件 除了 -datadir 和 -conf 以外的所有命令行参数都可以通过一个配置文件来设置,而所有配置文件中的选项也都可以在命令行中设置.命令行参数设置的值会覆盖配置 ...
- 访问WebServcie遇到配额不足的时候,请增加配额
常常遇到的报错: 1.错误一: Error in deserializing body of reply message for operation 'GetArticleInfo'.,StackTr ...
- c# 24种设计模式4建造者模式(Builder)
先来一个例子 建造者接口 public interface IBuilder { void CreateLogo(); void CreateBody(); void CreateWheel(); v ...
- c# 使用ssh.net 上传文件
在ssh.net 客户端实例下无法普通用户切换到su root 超级用户,原因是tty 的不支持,具体原因未查, 连接时用超级用户,问题解决 使用ssh.net 能实现远程命令, 使用其中的sf ...
- js的JSON
把任何JavaScript对象变成JSON,就是把这个对象序列化成一个JSON格式的字符串,这样才能够通过网络传递给其他计算机. 如果我们收到一个JSON格式的字符串,只需要把它反序列化成一个Java ...