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. y=y||'world'与y=y?y:'world'

    1.y=y||’world’ function log(x,y){ y=y||’world’; console.log(x,y) } log(‘hello’)===>hello world lo ...

  2. Python图像处理库(1)

    转自:http://www.ituring.com.cn/tupubarticle/2024 第 1 章 基本的图像操作和处理 本章讲解操作和处理图像的基础知识,将通过大量示例介绍处理图像所需的 Py ...

  3. Jenkins+maven+Tomcat配置发布

    jenkins大多数情况下都是用来部署Java项目,Java项目有一个特点是需要编译和打包的,一般情况下编译和打包都是用maven完成,所以系统环境中需要安装maven. 实验环境: 10.0.0.1 ...

  4. 【剑指offer】面试题 2. 实现 Singleton 模式

    面试题 2. 实现 Singleton 模式 题目:设计一个类,我们只能生成该类的一个实例. 单例模式:确保一个类只有一个实例,并提供了一个全局访问点. Java 实现 1.饿汉模式 //饿汉模式 p ...

  5. 数据库的主从复制常用Xshell命令

    mysql配置 1.设置数据库用户名和密码 mysqladmin -u root password "root" 2.打开3306端口号 iptables -I INPUT -p ...

  6. "The /usr/local directory is not writable."解决方法

    sudo chown -R $(whoami) /usr/local brew prune

  7. Protocol Buffers 在前端项目中的使用

    前言: 公司后端使用的是go语言,想尝试用pb和前端进行交互,于是便有了这一次尝试,共计花了一星期时间,网上能查到的文档几乎都看了一遍,但大多都是教在node环境下如何使用,普通的js环境下很多讲述的 ...

  8. Spiral Matrix(LintCode)

    Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...

  9. Codeforces GYM 101968 A. Tree Game

    差点自闭,感谢大佬帮忙找bug 题目:https://codeforces.com/gym/101968/problem/A 找树的重心+思维 找到树的重心,如果重心只有一个,以重心为根节点dfs,求 ...

  10. Bzoj1101 Zap(莫比乌斯反演)

    题面 Bzoj 题解 先化式子 $$ \sum_{x=1}^a\sum_{y=1}^b\mathbf f[gcd(x,y)==d] \\ = \sum_{x=1}^a\sum_{y=1}^b\sum_ ...