当前位置:网站首页>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]
};
```
边栏推荐
- MariaDb数据库管理系统的学习(一)安装示意图
- 2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
- 1292_ Implementation analysis of vtask resume() and xtask resume fromisr() in freeros
- 嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利
- The relationship between root and coefficient of quadratic equation with one variable
- Codeforces Round #274 (Div. 2) –A Expression
- Is it important to build the SEO foundation of the new website
- Basic introduction of figure
- 新入职一家公司需要去实践和注意的内容
- [asp.net core] set the format of Web API response data -- formatfilter feature
猜你喜欢

Reptile practice (V): climbing watercress top250

GPS从入门到放弃(十九)、精密星历(sp3格式)

Reset Mikrotik Routeros using netinstall

Why is the cluster mode of spark on Yan better than the client mode

Xiaoman network model & http1-http2 & browser cache

Enhance network security of kubernetes with cilium

抖音將推獨立種草App“可頌”,字節忘不掉小紅書?

Make menuconfig has a recipe for target 'menuconfig' failed error

PostgreSQL 修改数据库用户的密码

Unity3d Learning Notes 6 - GPU instantiation (1)
随机推荐
ViT论文详解
Guava: three ways to create immutablexxx objects
【sciter】: 基于 sciter 封装通知栏组件
GPS from getting started to giving up (XX), antenna offset
Microsoft technology empowerment position - February course Preview
[asp.net core] set the format of Web API response data -- formatfilter feature
MySQL removes duplicates according to two fields
LeetCode学习记录(从新手村出发之杀不出新手村)----1
zabbix 代理服务器 与 zabbix-snmp 监控
2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
十一、服务介绍及端口
保存和检索字符串
基于InsightFace的高精度人脸识别,可直接对标虹软
Uni app app half screen continuous code scanning
Yyds dry goods inventory C language recursive implementation of Hanoi Tower
The role of applicationmaster in spark on Yan's cluster mode
Reinforcement learning - learning notes 5 | alphago
PostgreSQL 安装gis插件 CREATE EXTENSION postgis_topology
Tiktok will push the independent grass planting app "praiseworthy". Can't bytes forget the little red book?
NPM run dev start project error document is not defined