414. Third Maximum Number
这个题有点坑啊。。主要是自己蠢,以为 Integer.MIN_VALUE -1 == -2147483649
public class Solution
{
public int thirdMax(int[] nums)
{
long max = (long)Integer.MIN_VALUE-1, mid = (long)Integer.MIN_VALUE-1, min = (long)Integer.MIN_VALUE-1;
for(int j: nums)
{
long i = (long)j;
if(i == max || i == min || i == mid) continue;
else if(i > max)
{
min = mid;
mid = max;
max = i;
}
else if(i > mid)
{
min = mid;
mid = i;
}
else if(i > min) min = i;
else continue;
}
if(min != (long)Integer.MIN_VALUE-1) return (int)min;
else if(max != (long)Integer.MIN_VALUE-1) return (int)max;
else return Integer.MIN_VALUE;
/*
[1,2,3,4,5]
[1,2,3,4,4,5,5]
[1,2,-2147483648]
*/
}
}
414. Third Maximum Number的更多相关文章
- 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 414 Third Maximum Number
Problem: 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 ...
- 414. Third Maximum Number数组中第三大的数字
[抄题]: Given a non-empty array of integers, return the third maximum number in this array. If it does ...
- LeetCode Array Easy 414. Third Maximum Number
Description Given a non-empty array of integers, return the third maximum number in this array. If i ...
- [Array]414. Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
- 【LeetCode】414. Third Maximum Number 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 替换最大值数组 使用set 三个变量 日期 题目地址 ...
- 【leetcode❤python】 414. Third Maximum Number
#-*- coding: UTF-8 -*- #l1 = ['1','3','2','3','2','1','1']#l2 = sorted(sorted(set(l1),key=l1.index,r ...
随机推荐
- java 更改list 某一元素?
if(!elTd.getElementsByTag("p").isEmpty()){ int i=eduList.size(); if(i>0){ ...
- oracle触发器调试
1.如下图位置点击触发器,会出现调试窗口 2.执行编译并调试 3.点击小虫,将画红位置,加入会触发此触发器的语句.如果触发器执行成功,不会出现第4个图,不成功,会出现数据调试信息,具体报错位置会定位到 ...
- ILMerge合并程序
在DOS窗口中,进入到ILMerge的安装目录 中 如图所示,之后写合并代码, 使用命令进行捆绑,以如图为例,将CSkin.dll和MyTool.exe捆绑成一个新的newtool.exe文件./ou ...
- wpf 自定义RadioButton控件样式
实现的效果为: 我感觉来自定义RadioButton样式和定义button空间的样式差不多,只是类型不同而已. 接下来分析一下样式代码: <!--自定义单选按钮样式--> & ...
- mahout的安装、配置及运行java程序
一.下载安装包: http://mahout.apache.org/general/downloads.html 二.解压: 将下载的安装包解压到需要的目录下 三.配置环境变量: export MAH ...
- ROW_NUMBER分页的注意事项
之前在使用ROW_NUMBER分页获取数据的时候,直接用ROW_NUMBER里的SELECT语句查出了所有的数据. like this: select * from ( select row_numb ...
- xml 个人练习2
package cn.gdpe.xml; import java.io.File;import java.io.FileInputStream;import java.io.IOException;i ...
- underscorejs-shuffle学习
2.21 shuffle 2.21.1 语法 _.shuffle(list) 2.21.2 说明 返回一个随机乱序的list副本数组, 使用 Fisher-Yates shuffle 来进行随机乱序. ...
- C# .NET3.5 改为 到.NET2.0 时 TypedTableBase 报错解决方法
NET 3.5 降版本 到.NET 2.0.不出意外,问题必然来了.编译错误一:错误 1 命名空间“System”中不存在类型或命名空间名称“Linq”(是缺少程序集引用吗?)解决:删掉该引用--没用 ...
- OpenGrok的安装
http://opengrok.github.io/OpenGrok/ Ubuntu环境下OpenGrok的安装及使用 http://www.linuxidc.com/Linux/2013-05/84 ...