LeetCode "Third Maximum Number"
Straight-forward strategy.. please take care of all details - data type, assignment order etc.
class Solution {
public:
int thirdMax(vector<int>& nums) {
long long v1, v2, v3;
v1 = v2 = v3 = std::numeric_limits<long long>::min();
size_t n = nums.size();
size_t cnt = ;
for(int i = ; i < n; i ++)
{
int v = nums[i];
if(v == v1 || v == v2 || v == v3) continue;
cnt ++;
if(v > v1)
{
v3 = v2;
v2 = v1;
v1 = v;
}
else if(v > v2)
{
v3 = v2;
v2 = v;
}
else if(v > v3)
{
v3 = v;
}
}
return cnt < ? v1 : v3;
}
};
LeetCode "Third Maximum Number"的更多相关文章
- [LeetCode] Third Maximum Number 第三大的数
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
- [LeetCode] Create Maximum Number 创建最大数
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...
- Leetcode: Create Maximum Number
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...
- Leetcode——Third Maximum Number
Question Given a non-empty array of integers, return the third maximum number in this array. If it d ...
- LeetCode 414. Third Maximum Number (第三大的数)
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
- C#版 - Leetcode 414. Third Maximum Number题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- 【leetcode】414. Third Maximum Number
problem 414. Third Maximum Number solution 思路:用三个变量first, second, third来分别保存第一大.第二大和第三大的数,然后遍历数组. cl ...
- [LeetCode] 321. Create Maximum Number 创建最大数
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...
- LeetCode 321. Create Maximum Number
原题链接在这里:https://leetcode.com/problems/create-maximum-number/description/ 题目: Given two arrays of len ...
随机推荐
- nexus7 二代 升级 android L
折腾了半天 ,最后发现其实很简单... 1.装好windows下gdb和bootloader的驱动,注意打开usb debug,另外进入bootloader是开机按电源键和音量减小键,至于要解锁这个想 ...
- HDU 4336 容斥原理 || 状压DP
状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...
- Unity jounal 2016-3-3
1. Project organization: 2.prefab Important part of the project, which seperate and organize the scr ...
- codeforces716E (点分治)
Problem Digit Tree 题目大意 给一棵树,有边权1~9. 询问有多少个点对(i,j),将i--j路径上的数字依次连接后所形成新数字可以被k整除.gcd(K,10)=1 解题分析 点分治 ...
- [驱动开发] windbg符号表
新建"环境变量 - 系统":_NT_SYMBOL_PATH 值为:SRV*FullDirPath*http://msdl.microsoft.com/download/symbol ...
- 问题:C++ 删除数组指针实用 delete []变量 汇编怎么实现的?
问题:C++ 删除数组指针实用 delete []变量 汇编怎么实现的?
- NPOI 格式设置2—时间,千分位,繁体,小数位
在Excel中我们经常要设置格式,比如说日期格式(yyyymmdd).小数点格式(1.20).货币格式($2000).百分比格式(99.99%)等等,这些东西在过去我们恐怕只能在服务器端生成好,不但增 ...
- 微信公众号红包接口开发PHP开发 CA证书出错,请登陆微信支付商户平台下载证书
微信红包接口调试过程中一直提示“CA证书出错,请登陆微信支付商户平台下载证书”,经反复调试,大致解决方法如下: 1.首先确保CA证书的路径是否正确,一定得是绝对路径,因为是PHP开发的,这里需要三个p ...
- Installscript如何给自定义路径的变量赋值
installscript自定义路径的赋值 TextSub("MY_WINDOWS_TEMP_SQL2008_DIR")="C:\\Windows\\temp2\\&q ...
- nginx 基本操作
nginx 是什么 nginx 是轻量.高性能的网页服务器,相较 Apache 占有内存小. 下载 https://nginx.org/en/download.html 默认根目录 安装目录下的 ht ...