当前位置:网站首页>The kth largest element in the [leetcode] array [215]
The kth largest element in the [leetcode] array [215]
2022-07-02 22:52:00 【When camellia flowers bloom.】
problem : Given an array of integers nums And integer k, Please return the... In the array k The biggest element
Please note that , What you need to look for is the number after array sorting k The biggest element , Not the first. k A different element
Example 1
Input : [3,2,1,5,6,4] and k = 2
Output : 5
Example 2
Input : [3,2,3,1,2,4,5,5,6] and k = 4
Output : 4
python3 Problem solving
# solution 1
def findKthLargest(nums, k):
nums.sort(reverse=True)
return nums[k-1]
findKthLargest([3,2,1,5,6,4],2) # 5
findKthLargest([3,2,3,1,2,4,5,5,6],4) # 4Knowledge points involved :
[Python] sort() Method VS sorted() function
https://blog.csdn.net/Hudas/article/details/122884550
边栏推荐
- [LeetCode] 数组中的第K个最大元素【215】
- 大话云原生之负载均衡篇-小饭馆客流量变大了
- Golang的学习路线
- php优化foreach中的sql查询
- Hanging mirror security won four global infosec awards on rsac2022
- JS solution for obtaining the width and height of hidden elements whose display is none
- Go 4 modes Singleton
- Golang面试整理 三 简历如何书写
- Golang interview finishing three resumes how to write
- 高并发介绍及应对
猜你喜欢

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)

UE4 游戏架构 学习笔记
![Gas station [problem analysis - > problem conversion - > greed]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
Gas station [problem analysis - > problem conversion - > greed]

Graphic view frame

Hanging mirror security won four global infosec awards on rsac2022

Jatpack------LiveData

Oracle-游标
![[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?](/img/b5/e746dd115995e82c93f667c58a601c.png)
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?

数组进阶提高

【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
随机推荐
[QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
Phpcms realizes the direct Alipay payment function of orders
【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
Storage unit conversion
The threshold value of fusing proportion cannot be changed with sentinel, and setting the slow call proportion has no effect
How should programmers write logs
Golang's learning route
I admire that someone explained such an obscure subject as advanced mathematics so easily
【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
JS solution for obtaining the width and height of hidden elements whose display is none
位的高阶运算
Golang的学习路线
Simpleitk use - 3 Common operations
wait解决僵尸进程
【板栗糖GIS】arcscene—如何做出有高度的高程图
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
UE4 UI adaptive screen
手写ORM(对象关系映射)增删改查
牛客网:龙与地下城游戏
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)