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. ActiveMQ基于JMS的pub/sub传播机制

    原文地址:[ActiveMQ实战]基于JMS的pub/sub传播机制 发布订阅模型 就像订阅报纸,我们可以选择一份或者多份报纸.比如:北京日报.人民日报.这些报纸就相当于发布订阅模型中的topic.如 ...

  2. Java学习笔记(七)——获取类中方法的信息,java的LinkedList

    [前面的话] 在实际项目中学习知识总是最快和最有效的,既能够较好的掌握知识,又能够做出点东西,还是简单的知识总结,最近一直在总结笔记,写的东西还是比较水,希望慢慢可以写出一些干货. 学习过程中的小知识 ...

  3. Ace Admin 学习笔记

    1. jqGrid  提交编辑数据,控制台报:Synchronous XMLHttpRequest on the main thread... jqGrid的选项设置async: true选项: aj ...

  4. gitlab备份与恢复

    (1)备份 1.创建备份目录,并授权 mkdir /data/backups/gitlab -pv chown -R git.git /data 2.修改gitlab配置 vim /etc/gitla ...

  5. php打开错误日志

    ini_set("display_errors", "On"); error_reporting(E_ALL | E_STRICT);

  6. mocha测试es6问题

    平时在写完正常的逻辑代码后,需要使用单元测试去测试逻辑代码,现在比较流行的是使用mocha进行测试 现在都是使用es6的写法,如果直接使用mocha test\某个文件,会出现下面的错误,原因是因为m ...

  7. 正对开源工作的源码管理web (ssh协议管理) 本地如何使用SourceTree 管理

    入口: 如何产生公钥与私钥 ,以及开源中国 gitweb sshkey 的管理web 地址: 点击 “头像” ,然后再头像下面的列表选择 “ SSH Key Settings” . 接下来,完成跟着步 ...

  8. 最正确的React事件绑定方式

    参考这篇文章:Choosing the Best Approach for React Event Handlers 1.function.bind()方式 2.inline arrow functi ...

  9. 洛谷——P2799 国王的魔镜

    P2799 国王的魔镜 题目描述 国王有一个魔镜,可以把任何接触镜面的东西变成原来的两倍——只是,因为是镜子嘛,增加的那部分是反的.比如一条项链,我们用AB来表示,不同的字母表示不同颜色的珍珠.如果把 ...

  10. CSS排版常用值指南

    高对比度是确保网页阅读无障碍的关键,但也往往会被过分强调. 白底黑子会让打断文本显得过分密集,反而影响可读性. 文字颜色 3b4348 链接颜色 235ea7 衬线字体 font-family: &q ...