【Leetcode_easy】747. Largest Number At Least Twice of Others
problem
747. Largest Number At Least Twice of Others
题意:
solution1:
class Solution {
public:
int dominantIndex(vector<int>& nums) {
int mx = -, secondMx = -, mxId = -;//err...
if(nums.size()<) return -;
for(int i=; i<nums.size(); i++)
{
if(nums[i]>mx)
{
secondMx = mx;
mx = nums[i];
mxId = i;
}
else if(nums[i]>secondMx) secondMx = nums[i];
}
return (*secondMx<=mx) ? mxId : -;
}
};
solution2:
class Solution {
public:
int dominantIndex(vector<int>& nums) {
int mx = INT_MIN, mxId = -;//err...
if(nums.size()<) return -;
for(int i=; i<nums.size(); i++)
{
if(nums[i]>mx) { mx = nums[i]; mxId = i; }
}
for(auto num:nums)
{
if(mx!=num && mx-num<num) return -;
}
return mxId;
}
};
参考
1. Leetcode_easy_747. Largest Number At Least Twice of Others;
2. Grandyang;
3. Discuss;
完
【Leetcode_easy】747. Largest Number At Least Twice of Others的更多相关文章
- 【LeetCode】747. Largest Number At Least Twice of Others 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 寻找两次最大值 排序 大顶堆 日期 题目地址:htt ...
- 【原创】leetCodeOj --- Largest Number 解题报告
原题地址: https://oj.leetcode.com/problems/largest-number/ 题目内容: Given a list of non negative integers, ...
- 【Leetcode】179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- 【Leetcode_easy】976. Largest Perimeter Triangle
problem 976. Largest Perimeter Triangle solution: class Solution { public: int largestPerimeter(vect ...
- 【Leetcode_easy】949. Largest Time for Given Digits
problem 949. Largest Time for Given Digits solution: class Solution { public: string largestTimeFrom ...
- 【Leetcode_easy】812. Largest Triangle Area
problem 812. Largest Triangle Area solution: class Solution { public: double largestTriangleArea(vec ...
- 【Leetcode_easy】762. Prime Number of Set Bits in Binary Representation
problem 762. Prime Number of Set Bits in Binary Representation solution1: class Solution { public: i ...
- 【Leetcode_easy】693. Binary Number with Alternating Bits
problem 693. Binary Number with Alternating Bits solution1: class Solution { public: bool hasAlterna ...
- 【LeetCode】813. Largest Sum of Averages 解题报告(Python)
[LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
随机推荐
- vue 组件的通信方式(完整版)
几种通信方式无外乎以下几种: Prop(常用) $emit (组件封装用的较多) .sync语法糖 (较少) $attrs & $listeners (组件封装用的较多) provide &a ...
- Codeforces Round #591
目录 Contest Info Solutions A. Save the Nature B. Sequence Sorting C. Paint the Tree D. Stack Extermin ...
- [转] C++ STL中map.erase(it++)用法原理解析
总结一下map::erase的正确用法. 首先看一下在循环中使用vector::erase时我习惯的用法: for(vector<int>::iterator it = vecInt.be ...
- Matlab学习——求解微分方程(组)
介绍: 1.在 Matlab 中,用大写字母 D 表示导数,Dy 表示 y 关于自变量的一阶导数,D2y 表示 y 关于自变量的二阶导数,依此类推.函数 dsolve 用来解决常微分方程(组)的求解问 ...
- Tomcat单独部署,控制台乱码解决方法
使用Tomcat作为容器,部署项目的时候,发现控制台总是乱码,乱码如下 打开Tomcat的部署目录 找到这一行,将UTF-8改成GBK java.util.logging.ConsoleHandler ...
- (转载):nmon使用
转:http://www.cnblogs.com/mululu/p/6398483.html 博客园 首页 新随笔 联系 管理 订阅 随笔- 76 文章- 1 评论- 2 Nmon的安装及使用 ...
- GO- 使用JSON
1 json.Marshal 把对象转换为JSON的方法 原型如下 func Marshal(v interface{}) ([]byte, error)这个函数接收任意类型的数据 v,并转换为字节 ...
- 2018-2019-2 20165222《网络对抗技术》Exp9 Web安全基础
1.实践过程记录 1.字符串型注入. 2.整数型注入 3.注入语句查看其他内容 4.xss是一种漏洞,这种漏洞允许用户输入脚本并且浏览器提交的时候不加编码.这种东西是最为流行并且有害的web应用的问题 ...
- git 删除目录及子目录下的同名文件
find . -name ".git" | xargs rm -Rf find . -name ".gitignore" | xargs rm -Rf
- 作妖 | "该文件没有与之关联的程序来执行该操作..."的解决方法(删除快捷方式小箭头所致)
文章目录 开始作妖 后悔作妖 终结作妖 开始作妖 这是次很作妖的体验过程.因为重新换了个系统,看着桌面上这些快捷方式都有个讨人嫌的小箭头,就在网上搜了搜解决办法. 比如,将下面的内容复制到记事本中,再 ...