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 ...
随机推荐
- 在WinForm应用程序中,使用选项卡控件来加载不同的Form界面!
TabPage tp=new TabPage(); your选项卡控件.Controls.Add(tp); From1 frm=new Form1(); frm.TopLevel = false; f ...
- ccui.ScrollView 扩展
大多数游戏都有背包这个东西. 道具列表通常用 ScrollView 来实现. 这个ScrollView内部有一个Layout, 滑动都是由移动这个Layout来实现. 道具摆放通常从上往下, 从左到右 ...
- [LeetCode OJ] Best Time to Buy and Sell Stock I
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- 【BZOJ1012】【树状数组求区间最值】最大数maxnumber
Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...
- ios开发相关网站
1.苹果开发者中心(ios Dev Center):最权威的学习ios开发的地方,提供ios开发所能用到的所有内容(包含文档.指南以及实例代码). https://developer.apple.co ...
- c++ string用法
首先,为了在我们的程序中使用string类型,我们必须包含头文件 .如下: #include //注意这里不是string.h string.h是C字符串头文件 1.声明一个C++字符串 声明一个字 ...
- dedecms织梦建站总结
说好要每月坚持写博客的,差一点就背弃自己的诺言了. 这一个月,除了修改magento站点和学习android外,一心都投在了为一家建筑公司做网站上去了,使用的是dedecms,我主要做的是前端开发,着 ...
- JS设置Cookie,及COOKIE的限制
在Javascript脚本里,一个cookie 实际就是一个字符串属性.当你读取cookie的值时,就得到一个字符串,里面当前WEB页使用的所有cookies的名称和值.每个cookie除了 name ...
- uboot总结:uboot配置和启动过程3(config.mk分析)
说明:文件位置:在uboot的目录下,文件名为:config.mk.是一个makefile文件,以后会被主Makefile调用. 它的主要作用的是: (1)具体的设置交叉编译工具链接(主Makefil ...
- Spark的RDD编程(二)公众号undefined110
创建RDD有两种方式:①读取外部数据集,lines=sc.textFile("README.md").②对一个集合进行并行化,lines=sc.parallelize([" ...