当前位置:网站首页>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]
};
```
边栏推荐
- Problems in the process of opencv300 cmake generating project
- numpy 下载安装
- From campus to Tencent work for a year of those stumbles!
- Why rdd/dataset is needed in spark
- Qt | UDP广播通信、简单使用案例
- [Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation
- zabbix 代理服务器 与 zabbix-snmp 监控
- What about the spectrogram
- GNN,请你的网络层数再深一点~
- [MySQL] online DDL details
猜你喜欢

Why rdd/dataset is needed in spark

PostgreSQL install GIS plug-in create extension PostGIS_ topology

20 large visual screens that are highly praised by the boss, with source code templates!
![Leetcode topic [array] -118 Yang Hui triangle](/img/77/d8a7085968cc443260b4c0910bd04b.jpg)
Leetcode topic [array] -118 Yang Hui triangle

50 commonly used numpy function explanations, parameters and usage examples
![[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation](/img/75/c0656c4890795bd65874b4f2b16462.jpg)
[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation

Unity3d Learning Notes 6 - GPU instantiation (1)

UNI-Admin基础框架怎么关闭创建超级管理员入口?

搜素专题(DFS )

Vit paper details
随机推荐
Realization of epoll reactor model
Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
语谱图怎么看
Aggregate function with key in spark
2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
爬虫实战(五):爬豆瓣top250
What about the spectrogram
Broadcast variables and accumulators in spark
经纪xx系统节点VIP案例介绍和深入分析异常
[asp.net core] set the format of Web API response data -- formatfilter feature
嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利
make menuconfig出现recipe for target ‘menuconfig‘ failed错误
GPS from entry to abandonment (XIV), ionospheric delay
GPS from getting started to giving up (16), satellite clock error and satellite ephemeris error
npm run dev启动项目报错 document is not defined
【MySQL】Online DDL详解
Tiktok will push the independent grass planting app "praiseworthy". Can't bytes forget the little red book?
What is the difference between animators and animators- What is the difference between an Animator and an Animation?
关于char[]数组通过scanf赋值使用上的一些问题。。
hdu 4912 Paths on the tree(lca+馋)