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. 【linux】su和sudo命令的区别

    来源:http://www.jb51.net/LINUXjishu/12713.html 一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比 ...

  2. python 字典value排序

    #!/usr/bin/env python#coding:utf-8s = {“a”:1,”b”:3,”c”:2} print sorted(s.iteritems(),key=lambda t:t[ ...

  3. 在cmd 中输入了错误mysql命令后,如何退出?

    例如: mysql> select * from tb_name          '>          '>          '>          '> 由于输错 ...

  4. LeetCode解题报告—— Interleaving String

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = ...

  5. poj 1692(动态规划)

    Crossed Matchings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2711   Accepted: 1759 ...

  6. python读写hdf5及cdf格式文件

    Python write and read hdf5 file http://stackoverflow.com/questions/20928136/input-and-output-numpy-a ...

  7. stl 学习笔记

    1. Erasing multiple objects from a std::vector https://stackoverflow.com/questions/3487717/erasing-m ...

  8. Redis安装+密码认证

    redis: 安装: $ wget http://download.redis.io/releases/redis-3.2.7.tar.gz $ tar xzf redis-3.2.7.tar.gz ...

  9. Java8之Stream/Map

    本篇用代码示例结合JDk源码讲了Java8引入的工具接口Stream以及新Map接口提供的常用默认方法.    参考:http://winterbe.com/posts/2014/03/16/java ...

  10. 史上最全的web前端系统学习教程!

    这份资料整理花了近7天,如果感觉有用,可以分享给更有需要的人. 在看接下的介绍前,我先说一下整理这份资料的初衷: 我的初衷是想帮助在这个行业发展的朋友和童鞋们,在论坛博客等地方少花些时间找资料,把有限 ...