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 ...
随机推荐
- UIkit框架之uiUIapplication
1.继承链:uiresponder:NSObject 2.使用 sharedApplication方法来存取对象 3.这个类可以遵守协议是UIApplicationDelegate 4.获取app的实 ...
- Java的流程控制和C++的异同
Java的流程控制和C++基本相似 现将不同的地方总结一下,以便快速掌握. Java的特殊流程控制的特殊部分: 1.顺序结构 -- 没有区别 2.分之结构 -- 没有区别 3.循环结构 1> ...
- 【RobotFramework】Selenium2Library类库关键字使用说明
Add CookieArguments:[ name | value | path=None | domain=None | secure=None | expiry=None ]Adds a coo ...
- vi & vim复制,粘贴,剪切文本
我经常用vi编辑器,但基本上还是windows的习惯,没有系统的学过其功能,今天遇到了文本的复制这没有办法了,查看一下解决如下: 引用文本: ----------------------------- ...
- 简述reflow和repaint
今天在看面试题的时候遇到reflow和repaint的问题,以前并没有接触过,所以拿来学习一下~ reflow 和 repaint 会拖慢浏览器的速度,而且用户和Web页面都不能在 reflow 和 ...
- wamp apache 的虚拟机配置 多域名访问 的 三部曲
wamp apache 的虚拟机配置 多域名访问 的 三部曲 wamp: 1:C:\WINDOWS\system32\drivers\etc->hosts 加入自己的 ...
- 【转】我是如何在SQLServer中处理每天四亿三千万记录的
原文转自:http://blog.jobbole.com/80395/ 首先声明,我只是个程序员,不是专业的DBA,以下这篇文章是从一个问题的解决过程去写的,而不是一开始就给大家一个正确的结果,如果文 ...
- UI控件
1.布局:一个Activity相当于一个手机屏幕默认和手机屏幕的宽高相同LinearLayout.RelativeLayout等布局继承了ViewGroup,ViewGroup是View的子类,可以容 ...
- 读取手机上所有应用程序并显示(APP)
pd = ProgressDialog.show(getActivity(), "请稍候..", "正在收集软件信息...", true,false); Thr ...
- js倒计时跳转链接
(function(){ var loadUrl = 'http://www.cnblogs.com/naokr/',//跳转链接 loadTime = 3000,//跳转时间 reTime = 10 ...