LeetCode Third Maximum Number
题意:求数组中第三大的数,重复的数不算
思路:用三个变量记录第一大,第二大,第三大的数,在遍历数据过程中更新这三个值。
具体代码如下:
public class Solution
{public int thirdMax(int[] nums){long first, second, third;first = second = third = Long.MIN_VALUE;for (int num : nums){if (num == first || num == second || num == third) continue;if (num > first){third = second;second = first;first = num;}else if (num > second){third = second;second = num;}else if (num > third) third = num;}return (third == Long.MIN_VALUE) ? (int)first : (int)third;}
}
LeetCode Third Maximum Number相关推荐
- leetcode 1937. Maximum Number of Points with Cost
题目 解法:暴力动态规划,tle 三维的dp,提交不能通过 class Solution {public:long long maxPoints(vector<vector<int> ...
- LeetCode 第201次周赛 1546. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target
Leetcode 1546. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target 题目描述 思路 周赛代码 优化代码 ...
- leetcode 330. Patching Array | 1798. Maximum Number of Consecutive Values You Can Make
1798. Maximum Number of Consecutive Values You Can Make | 1798. 你能构造出连续值的最大数目 https://leetcode.com/p ...
- LeetCode——1937. 扣分后的最大得分(Maximum Number of Points with Cost)[中等]——分析及代码(Java)
LeetCode--1937. 扣分后的最大得分[Maximum Number of Points with Cost][中等]--分析及代码[Java] 一.题目 二.分析及代码 1. 动态规划 ( ...
- LeetCode 414. Third Maximum Number
题目: Given a non-empty array of integers, return the third maximum number in this array. If it does n ...
- C#LeetCode刷题之#414-第三大的数(Third Maximum Number)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3710 访问. 给定一个非空数组,返回此数组中第三大的数.如果不存 ...
- LeetCode | 414. Third Maximum Number
. 题目 Given an integer array nums, return the third distinct maximum number in this array. If the thi ...
- LeetCode 421. Maximum XOR of Two Numbers in an Array--Python解法
LeetCode 421. Maximum XOR of Two Numbers in an Array–C++,Python解法 LeetCode题解专栏:LeetCode题解 我做的所有的Leet ...
- 【动态规划】LeetCode 53. Maximum Subarray
LeetCode 53. Maximum Subarray 原题描述(求子序列最大和/最大子串):Find the contiguous subarray within an array (conta ...
最新文章
- input不管用 vue_Vue自定义指令实现快速读取Excel
- java常量信用_JAVA常量
- 030_vue命名路由
- laravel 分页php_laravel 分页 seo浅谈
- python樱花代码_使用python图形模块turtle库绘制樱花、玫瑰、圣诞树代码实例
- INFO:安装包文件共享(Shared Files)设置注意事项
- Flask碰到 原因:CORS 头缺少 'Access-Control-Allow-Origin'解决方案 解决
- Spring BeanFactory 容器
- java shiro security_安全框架Shiro和SpringSecurity的比较
- Spring Cloud微服务系列-Eureka Client源码解析(二)
- 充电枪cp信号控制板_新能源汽车充电头气密性检测是怎么做的呢?
- C++多态的练习——编写一个计算器项目
- 关于Team Building
- 风能设备物流的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
- 菜鸟站长之家教各位菜鸟站长用WordPress如何给文章生成推广二维码
- 520催泪感人表白心动文案怎么用免费的记笔记软件记录?
- Invalid bound statement (not found): com.itheima.mapper.userMapper.SelectAll
- Ubuntu文件查找命令集合
- 最大进程线程数 连接数
- ORACLE学习笔记(6)(分析函数)
热门文章
- 20150917html第二次课
- 自学python找工作工资-大四应届毕业生,学了两个月Python,找工作感觉好难啊?...
- python3项目-30 个惊艳的Python开源项目
- 笔记本电脑下载python视频教程-Python的Jupyter Notebook入门教程
- python数据类型-Python3基本数据类型(一、数字类型)
- python的工作方向-Python的就业的方向和前景
- python能在生活中做什么-Python能在生活中做什么
- python3下载安装配置-Linux 安装python3.7.3
- python自动化办公培训排名-盘点使用Python进行自动化办公所需要的知识点
- python一千行入门代码-Python – 一次从文件中读取1000行