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"的更多相关文章

  1. [LeetCode] Third Maximum Number 第三大的数

    Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...

  2. [LeetCode] Create Maximum Number 创建最大数

    Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...

  3. Leetcode: Create Maximum Number

    Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...

  4. Leetcode——Third Maximum Number

    Question Given a non-empty array of integers, return the third maximum number in this array. If it d ...

  5. 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 ...

  6. C#版 - Leetcode 414. Third Maximum Number题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  7. 【leetcode】414. Third Maximum Number

    problem 414. Third Maximum Number solution 思路:用三个变量first, second, third来分别保存第一大.第二大和第三大的数,然后遍历数组. cl ...

  8. [LeetCode] 321. Create Maximum Number 创建最大数

    Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...

  9. LeetCode 321. Create Maximum Number

    原题链接在这里:https://leetcode.com/problems/create-maximum-number/description/ 题目: Given two arrays of len ...

随机推荐

  1. WebSocket通信协议

    var ws = new WebSocket("ws://echo.websocket.org"); ws.onopen = function(){ws.send("Te ...

  2. Appium常用的API函数

    在学习应用一个框架之前,应该了解一下这个框架的整体结构或是相应的API函数.这篇文章还不错:http://blog.sina.com.cn/s/blog_68f262210102vzf9.html,就 ...

  3. python-selenium之firefox、Chrome、Ie运行

    测试脚本是否支持在不同浏览器运行firefox浏览器运行脚本 from selenium import webdriver driver=webdriver.Firefox() driver.get( ...

  4. EM界面 ORA-12505: TNS: 监听程序当前无法识别连接描述符中所给出的 SID (DBD ERROR: OCIServerAttach)

    我的是10g,打开EM,另外都正常,就有这个问题到实例的代理连接 状态 失败 详细资料 ORA-12505: TNS: 监听程序当前无法识别连接描述符中所给出的 SID (DBD ERROR: OCI ...

  5. C#面向接口编程详解(1)——思想基础

    我想,对于各位使用面向对象编程语言的程序员来说,“接口”这个名词一定不陌生,但是不知各位有没有这样的疑惑:接口有什么用途?它和抽象类有什么区别?能不能用抽象类代替接口呢?而且,作为程序员,一定经常听到 ...

  6. C++构造函数与虚表覆盖

    在涉及到虚函数的情况下,C++构造函数的构造顺序为:先调用构造函数,虚表指针初始化,用户代码:如涉及到多重继承情况,初始化顺序为基类.子类(从左至右),假设一个类的继承情况如下图,其初始化顺序为:Po ...

  7. SOAP Webservice和RESTful Webservice

    http://blog.sina.com.cn/s/blog_493a845501012566.html REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的 ...

  8. HTML 兼容性

    1. 不同浏览器对HTML标记所具有的内外边距属性具有不同的定义. 2. 因此如果想消除这种差距,应该在相应的CSS部分加入以下CSS代码: *{margin:0px;padding:0px;} 优先 ...

  9. JavaScript:修改作用域外变量

    今天在看JavaScript学习指南的时候做的课后习题,也因此详细的对函数的传入参数进行比较深入的研究. 题目如下: 函数如何才能修改其作用域之外的变量?编写一个函数,由1~5的数字组成的数组作为参数 ...

  10. springMvc3.0.5搭建全程 (转)

    用了大半年的Spring MVC3.0,用着感觉不错.简单写一个搭建Spring MVC3.0的流程(以Spring3.0.5为列),数据库交互使用spring JDBC Template,附件有项目 ...