https://leetcode.com/problems/third-maximum-number/

// 开始我以为相同的也占一位,比如5,3,3,2,得出3,但是答案是需要2

public class Solution {

    public int thirdMax(int[] nums) {
List<Integer> lst = new ArrayList<>();
boolean equal;
int tmp; for (int i=0; i<nums.length; i++) {
equal = false;
int j=0;
for (;j<3&&j<lst.size(); j++) {
tmp = lst.get(j);
if (tmp == nums[i]) {
equal = true;
break;
}
else if (tmp < nums[i]) {
break;
}
}
if (!equal && j<3)
lst.add(j, nums[i]);
} if (lst.size() < 3) {
if (lst.size() > 0) {
return lst.get(0);
}
return 0;
} return lst.get(2); } /*
public int thirdMax(int[] nums) {
List<Integer> lst = new ArrayList<>();
for (int i=0; i<3 && i<nums.length; i++) {
int j=0;
for (;j<lst.size(); j++) {
if (lst.get(j) <= nums[i]) {
break;
}
}
lst.add(j, nums[i]);
} if (lst.size() < 3) {
if (lst.size() > 0) {
return lst.get(0);
}
return 0;
} for (int i=3; i<nums.length; i++) {
int j = 0;
for (; j<3; j++) {
if (lst.get(j) < nums[i]) {
break;
}
}
if (j<3) {
lst.add(j, nums[i]);
}
}
return lst.get(2); }
*/
}

third-maximum-number的更多相关文章

  1. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

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

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

  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 414 Third Maximum Number

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

  5. Failed to connect to database. Maximum number of conections to instance exceeded

    我们大体都知道ArcSDE的连接数有 48 的限制,很多人也知道这个参数可以修改,并且每种操作系统能支持的最大连接数是不同的. 如果应用报错:超出系统最大连接数 该如何处理? 两种解决办法: 第一,首 ...

  6. POJ2699 The Maximum Number of Strong Kings

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2102   Accepted: 975 Description A tour ...

  7. [LintCode] Create Maximum Number 创建最大数

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

  8. tomcat 大并发报错 Maximum number of threads (200) created for connector with address null and port 8080

    1.INFO: Maximum number of threads (200) created for connector with address null and port 8091 说明:最大线 ...

  9. iOS真机调试问题-App installation failed,The maximum number of apps for free development profiles has been reached.

    The maximum number of apps for free development profiles has been reached. 源引:http://www.jianshu.com ...

  10. POJ 2699 The Maximum Number of Strong Kings Description

    The Maximum Number of Strong Kings   Description A tournament can be represented by a complete graph ...

随机推荐

  1. hdu 2883(构图+最大流+压缩区间)

    kebab Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. “无法在web服务器上启动调试,不是Debugger User组成员..."

    在使用VS.net2003开发asp.net项目时,有时候在你调试项目时,会提示”无法在web服务器上启动调试,不是Debugger User组成员..."这样一个错误信息.很是让人头疼,一 ...

  3. Linux之父Linus的8个趣闻轶事

    博客中的文章均为 meelo 原创,请务必以链接形式注明本文地址 <只是为了好玩:Linux之父林纳斯自传>是一本很古老的书了,2001年就有了中文版,在2014的时候图灵图书又把它重新翻 ...

  4. 64位直接加载个img 标签的src

  5. 经验分享:如何系统学习 Web 前端技术?

    这篇文章主要是面向小白用户的,如果你有些基础,当然也建议你看看,尤其是最后一个主题,或许你能得到一些启发.本文的观点,纯属个人自以为是的想法,不是真理,仅供参考. 抛开具体技术细节,先主要谈谈程序员如 ...

  6. Python 实现腾讯新闻抓取

    原文地址:http://www.cnblogs.com/rails3/archive/2012/08/14/2636780.htm 思路: 1.抓取腾讯新闻列表页面: http://news.qq.c ...

  7. 【我要学python】爬虫准备之了解基本的html标签

    HTML 标题 <h1>This is a heading</h1> HTML 段落 <p>This is a paragraph.</p> HTML ...

  8. CodeForces 809D Hitchhiking in the Baltic States(FHQ-Treap)

    题意 给你长度为$n$的序列,序列中的每个元素$i$有一个区间限制$[l_i,r_i]$,你从中选出一个子序列,并给它们标号$x_i$,要求满足 $,∀i<j,x_i<x_j$,且$, ∀ ...

  9. 设计模式-迭代器模式(Iterator Pattern)

    本文由@呆代待殆原创,转载请注明出处:http://www.cnblogs.com/coffeeSS/ 迭代器模式简介 迭代器相信大部分人都不陌生,java/c++等很多编程语言的容器类都支持迭代器操 ...

  10. Beaglebone Black教程使用SSH通过USB和因特网连接Beaglebone Black

    Beaglebone Black教程使用SSH通过USB和因特网连接Beaglebone Black 使用SSH通过USB和因特网连接Beaglebone Black SSH是Secure Shell ...