当前位置:网站首页>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]
};
```
边栏推荐
- Aggregate function with key in spark
- [daily] win10 system setting computer never sleeps
- MongoDB(三)——CRUD
- GPS从入门到放弃(十八)、多路径效应
- What is the RDD operator in spark
- 美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断
- JPEG2000-Matlab源码实现
- GPS from entry to abandonment (XVII), tropospheric delay
- 功能强大的国产Api管理工具
- [Yu Yue education] reference materials for surgical skills teaching in Tongji University
猜你喜欢
ViT论文详解
一行代码可以做些什么?
LeetCode:1189. The maximum number of "balloons" -- simple
GPS从入门到放弃(十四)、电离层延时
Some problems about the use of char[] array assignment through scanf..
Xiaoman network model & http1-http2 & browser cache
GPS從入門到放弃(十三)、接收機自主完好性監測(RAIM)
关于char[]数组通过scanf赋值使用上的一些问题。。
[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation
1292_ Implementation analysis of vtask resume() and xtask resume fromisr() in freeros
随机推荐
1D convolution detail
Michael smashed the minority milk sign
11、 Service introduction and port
VIP case introduction and in-depth analysis of brokerage XX system node exceptions
GPS from getting started to giving up (XV), DCB differential code deviation
强化学习-学习笔记5 | AlphaGo
[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation
Sequoia China, just raised $9billion
GNN,请你的网络层数再深一点~
HDU 2008 digital statistics
bat脚本学习(一)
MySQL removes duplicates according to two fields
zabbix 代理服务器 与 zabbix-snmp 监控
Xiaoman network model & http1-http2 & browser cache
语谱图怎么看
What about the spectrogram
PostgreSQL modifies the password of the database user
The underlying implementation of string
Reset Mikrotik Routeros using netinstall
华为在多个行业同时出击,吓人的技术让欧美企业瑟瑟发抖