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. 自动化运维之saltstack的使用安装

    SaltStack 简介 SaltStack是一个服务器基础架构集中化管理平台,具备配置管理.远程执行.监控等功能,基于Python语言实现,结合轻量级消息队列(ZeroMQ)与Python第三方模块 ...

  2. 在JAVASCRIPT中构建一个复杂的对象,并用JSON进行转换

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. centos7 安装rlwrap

    https://blog.csdn.net/zhjmozhi/article/details/78347216

  4. Oracle 数据库分页查询的三种方法

    一.Oracle 数据库分页查询的三种方法 1.简介 不能对 rownum 使用 >(大于或等于 1 的数值).>=(大于 1 的数值).=(不等于 1 的数值),否则无结果.所以直接用 ...

  5. Ubuntu下各种环境变量设置

    1.用户目录下的 .bashrc 文件在用户主目录下,有一个 .bashrc 文件,编辑该文件:$gedit ~/.bashrc 在最后边加入需要设置变量的shell语句,例如:export PATH ...

  6. phpstorm如何进行文件或者文件夹重命名

    1.phpstorm的重构 1.1重命名 在phpstorm中,右键点击我们要进行修改的文件,然后又一项重构,我们就可以进行对文件的重命名. 接下来点击重命名进行文件或者文件夹的重新命名. 在框中输入 ...

  7. 关于公众号JavaTokings侵权声明

    该公众号几乎有所有文章都是在未经原作者的同意下私自将文章转移至其公众号.其中 [消息中间件ActiveMQ使用详解](链接是:https://www.cnblogs.com/yanfei1819/p/ ...

  8. 1、编译安装Nginx

    1.1 如何选择web服务器 在实际工作中,我们需要根据业务需求来选择合适的业务服务软件,有关web服务,选择建议如下: 静态业务:若是高并发场景,尽量采用nginx或lighttpd,二者首选ngi ...

  9. 【爬虫】python requests模拟登录知乎

    需求:模拟登录知乎,因为知乎首页需要登录才可以查看,所以想爬知乎上的内容首先需要登录,那么问题来了,怎么用python进行模拟登录以及会遇到哪些问题? 前期准备: 环境:ubuntu,python2. ...

  10. Python开发基础-Day6-函数参数、嵌套、返回值、对象、命名空间和作用域

    函数的使用原则 函数的使用必须遵循:先定义后使用的原则 函数的定义,与变量的定义是相似的,如果没有事先定义函数而直接引用就相当于在引用一个不存在变量名 定义阶段:只检测语法,不执行代码,当出现语法错误 ...