当前位置:网站首页>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]
};
```
边栏推荐
- Write a rotation verification code annotation gadget with aardio
- Vit paper details
- Aggregate function with key in spark
- GPS du début à l'abandon (XIII), surveillance autonome de l'intégrité du récepteur (raim)
- Unity3D学习笔记6——GPU实例化(1)
- 【sciter】: 基于 sciter 封装通知栏组件
- Five wars of Chinese Baijiu
- 保存和检索字符串
- ViT论文详解
- Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1
猜你喜欢
Leetcode topic [array] -118 Yang Hui triangle
Checkpoint of RDD in spark
Yyds dry goods inventory C language recursive implementation of Hanoi Tower
1292_FreeROS中vTaskResume()以及xTaskResumeFromISR()的实现分析
[Chongqing Guangdong education] Information Literacy of Sichuan Normal University: a new engine for efficiency improvement and lifelong learning reference materials
GPS从入门到放弃(十五)、DCB差分码偏差
PostgreSQL install GIS plug-in create extension PostGIS_ topology
The golden age of the U.S. technology industry has ended, and there have been constant lamentations about chip sales and 30000 layoffs
嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利
Broadcast variables and accumulators in spark
随机推荐
ViT论文详解
功能强大的国产Api管理工具
LeetCode:1189. The maximum number of "balloons" -- simple
关于char[]数组通过scanf赋值使用上的一些问题。。
make menuconfig出现recipe for target ‘menuconfig‘ failed错误
About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness
UNI-Admin基础框架怎么关闭创建超级管理员入口?
JS method to stop foreach
强化学习-学习笔记5 | AlphaGo
Kohana database
GPS从入门到放弃(十三)、接收机自主完好性监测(RAIM)
guava:Collections. The collection created by unmodifiablexxx is not immutable
zabbix 代理服务器 与 zabbix-snmp 监控
MySQL - transaction details
MySQL related terms
MySQL removes duplicates according to two fields
Codeforces Round #274 (Div. 2) –A Expression
保存和检索字符串
关于程序员的职业操守,从《匠艺整洁之道》谈起
Kohana 数据库