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 ...
随机推荐
- RESTful互联网框架
在我们日常接触的网络中,对于非程序员来说主要关注的就是在网上找到自己需要的资料,但是对于开发者来说,主要关注的就是将结构和页面,以及功能的分离,但是如何划分这个结构呢,或许我们知道的有MVC框架,甚至 ...
- slf4j与log4j
推荐使用SLF4J(Simple Logging Facade for Java)作为日志的api,SLF4J是一个用于日志系统的简单Facade,允许最终用户在部署其应用时使用其所希望的日志系统. ...
- 几种不同存储形式下的数据挖掘问题[ZZ]
从原理上说,数据挖掘应该可以应用到任何信息存储方式的知识挖掘中,但是挖掘的挑战性和技术会因为源数据的存储类型的不同而不同.特别是,近年来的研究表明数据挖掘所涉及的数据存储类型越来越丰富,除了一些有通用 ...
- javascript——面向对象程序设计(1)
<script type="text/javascript"> //ECMA-262把对象定义为:“无序属性的 集合,其属性可以包含基本值.对象或者函数” //理解对象 ...
- 计算机天才Aaron Swartz 名作 《如何提高效率》——纪念真正的“hacker"!
如何提高效率 <HOWTO: Be more productive>(如何提高效率)作者:Aaron Swartz 肯定有人跟你说过这样的话,“你有看电视的那么长时间,都可以用来写一本书了 ...
- 【转】ThinkPHP中数据库操作返回值总结
Thinkphp中的Think\Model类提供了数据库的基本CURD(Create.Update.Read及Delete),通过该类可以很便捷的进行操作.Model类及扩展类主要的方法有: Crea ...
- 手工构建ISO的基本步骤
1.完成rpm包的构建 登录测试机,ssh 10.xx.xx.xxx cd /home/svn/desktop/trunk/ svn update ...
- Content-Type实体首部字段
现代互联网下,每天都会有数以亿计的各种媒体对象经由HTTP传输,如图像,文本,影视以及软件程序等.这些数据都包含在HTTP报文的实体内容中,如果把HTTP报文想像成一份快递,HTTP实体就是快递实 ...
- ha666_go运行环境配置
项目地址:http://git.oschina.net/ha666/ha666_go 服务器配置: CPU: 1核 内存: 1024 MB 操作系统: CentOS 7.0 64位 内网IP: 10. ...
- All in All
Crawling in process... Crawling failed Description You have devised a new encryption technique which ...