当前位置:网站首页>414. The third largest digital buckle
414. The third largest digital buckle
2022-07-06 22:04:00 【Big chicken legs are best】
Give you a non empty array , Returns the value in this array The third largest number . If it doesn't exist , Then return the maximum number in the array .
Example 1:
Input :[3, 2, 1]
Output :1
explain : The third largest number is 1 .
Example 2:
Input :[1, 2]
Output :2
explain : The third largest number doesn't exist , So return the maximum number 2 .
Example 3:
Input :[2, 2, 3, 1]
Output :1
explain : Be careful , Ask to return the third largest number , It's the third largest of all the different numbers .
There are two values in this example that are 2 Number of numbers , They're both second . The third largest of all the different numbers is 1 .
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/third-maximum-number
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
### Their thinking
Here is the solution
Sort from
### Code
```javascript
/**
* @param {number[]} nums
* @return {number}
*/
var thirdMax = function(nums) {
nums=[...new Set(nums.sort((a,b)=>{return a-b}))]
let len=nums.length
if(len<3)return nums[len-1]
return nums[len-3]
};
```
边栏推荐
- AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
- AI 企业多云存储架构实践 | 深势科技分享
- GPS从入门到放弃(十一)、差分GPS
- 1292_ Implementation analysis of vtask resume() and xtask resume fromisr() in freeros
- Mongodb (III) - CRUD
- LeetCode:1189. The maximum number of "balloons" -- simple
- Xiaoman network model & http1-http2 & browser cache
- VIP case introduction and in-depth analysis of brokerage XX system node exceptions
- mysql根据两个字段去重
- Some problems about the use of char[] array assignment through scanf..
猜你喜欢
Powerful domestic API management tool
guava:Collections. The collection created by unmodifiablexxx is not immutable
Xiaoman network model & http1-http2 & browser cache
Michael smashed the minority milk sign
【sciter】: 基于 sciter 封装通知栏组件
Method return value considerations
美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断
小满网络模型&http1-http2 &浏览器缓存
GPS从入门到放弃(十四)、电离层延时
What can one line of code do?
随机推荐
Guava: use of multiset
强化学习-学习笔记5 | AlphaGo
C language: comprehensive application of if, def and ifndef
From campus to Tencent work for a year of those stumbles!
MPLS experiment
Enhance network security of kubernetes with cilium
Tiktok will push the independent grass planting app "praiseworthy". Can't bytes forget the little red book?
语谱图怎么看
C language char, wchar_ t, char16_ t, char32_ Relationship between T and character set
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
Checkpoint of RDD in spark
GPS从入门到放弃(十二)、 多普勒定速
PostgreSQL 修改数据库用户的密码
Unity3D学习笔记6——GPU实例化(1)
[Chongqing Guangdong education] Tianjin urban construction university concrete structure design principle a reference
JPEG2000-Matlab源码实现
Reptile practice (V): climbing watercress top250
GPS from getting started to giving up (XV), DCB differential code deviation
zabbix 代理服务器 与 zabbix-snmp 监控
About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness