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 ...
随机推荐
- 转-SecureCRT设置
原帖地址:http://www.2cto.com/os/201410/341569.html 一.基本设置 1.修改设置 为了SecureCRT用起来更方便,需要做一些设置,需要修改的有如下几处: 1 ...
- applicationContext.xml详解(转)
转自:http://blog.csdn.net/heng_ji/article/details/7022171,写的很好,省得以后找,放此处 想必用过Spring的程序员们都有这样的感觉,Spring ...
- Linux系统、版本、CPU、内存查看、硬盘空间
查看系统版本:lsb_release -a [root@localhost /]# lsb_release -a LSB Version: :core-4.0-amd64:core-4.0-no ...
- yzoi1777倒水问题的详细解法
Description - 问题描述 x.y.z三个容器,其最大容量分别是xMAX升.yMAX升.zMAX升,这里规定100>xMAX>yMAX>zMAX.一开始x是装满了水的,现在 ...
- js 强制转换
强制转换为布尔类型: <script> var text =Boolean(0) //=>以下转换的类型都为false text = Boolean(0.0) text = Bool ...
- 基于Qt QGraphicsView的多点触摸绘图
本应用于基于QGraphicsView框架,实现多点触摸. 工程仅仅演示了多点触摸绘图,源自我前段时间一款基于Qt的绘图软件. 工程结构: kmp.h 定义了枚举 slide.h/cpp 定义了派生于 ...
- Github Https方式push错误”Empty reply from server”
1 2 3 4 5 6 7 8 9 10 2014-11-19 20:41:30.130 GitHub for Mac Login[2595:326257] AskPass ...
- unity3d中的http通信 二
转载自 http://www.cnblogs.com/88999660/archive/2013/03/11/2954279.html 如果侵权,请及时通知我删除! using System; usi ...
- java.lang.String.indexOf()用法
java.lang.String.indexOf(char ch) 方法返回字符ch在指定字符串中第一次出现的下标索引位置 如果字符ch在指定的字符串中找不到,则返回-1 示例: import jav ...
- html里的table如何在表格内部保留表格横线的同时去掉表格里的竖线
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...