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 ...
随机推荐
- CGBitmapContextCreate函数参数详解
函数原型: CGContextRef CGBitmapContextCreate ( void *data, size_t width, size_t height, size_t bitsPerCo ...
- 【转】C#多线程示例
using System; using System.Threading; namespace ConsoleThread { class ThreadApp { static int interva ...
- nginx做nodejs(express等通用)反向代理
首先配置环境nginx+nodejs...(没有请看我的其他文章,此处不重复) cd 到nginx的site-available目录 ubuntu的在 cd /etc/nginx/site-avail ...
- 解决JS中各浏览器Date格式不兼容的问题
IE,Chrome和FireFox等浏览器都支持的一种日期格式是:2015/11/30 19:29:23. 所以,可以这样写: var timeStr = new Date("2015/11 ...
- Tomcat version 7.0 only support J2EE 1.2。。。。。。。
刚开始使用eclipse编程,换了eclipse版本后导入项目,出现下的报错
- 细节小bug
1. function devChange(value){ $("#multipleLeft").empty(); ReportRemote.getDeviceFlow(value ...
- C++学习笔记27:异常处理机制
一.异常处理机制基础 异常的定义 程序中可以检测的运行不正常的情况 异常处理的基本流程 某段程序代码在执行操作时发生特殊情况,引发一个特定的异常 另一段程序代码捕获该异常并处理它 二.异常的引发 th ...
- Kafka Topic ISR不全,个别Spark task处理时间长
现象 Spark streaming读kafka数据做业务处理时,同一个stage的task,有个别task的运行时间比多数task时间都长,造成业务延迟增大. 查看业务对应的topic发现当topi ...
- imshow() displays a white image for a grey image
Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 ...
- CLR via C# 3rd - 07 - Constants and Fields
1. Constants A constant is a symbol that has a never-changing value. When defining a constant ...