当前位置:网站首页>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
边栏推荐
- NC24325 [USACO 2012 Mar S]Flowerpot
- Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
- Dynamic memory allocation (malloc calloc realloc free)
- UE4 UI adaptive screen
- Storage unit conversion
- [Luogu p1541] tortoise chess [DP]
- 电商系统微服务架构
- 《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
- 《乔布斯传》英文原著重点词汇笔记(十一)【 chapter nine】
- [LeetCode] 存在重复元素【217】
猜你喜欢

wait解决僵尸进程
![[LeetCode] 数组中的第K个最大元素【215】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 数组中的第K个最大元素【215】

Oracle-PL/SQL编程

杰理之、产线装配环节【篇】

Dahua cloud native load balancing article - the passenger flow of small restaurants has increased

Socket套接字C/S端流程

Socket socket c/s end process

分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少

Oracle PL / SQL programming

Hanging mirror security won four global infosec awards on rsac2022
随机推荐
#include errors detected. Please update your includePath.
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
I admire that someone explained such an obscure subject as advanced mathematics so easily
Struct, bit segment, enumeration, union
Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
Task and privilege level protection
U++ 学习笔记 堆
Go 4 modes Singleton
P1007 独木桥
[QT] QT multithreading development - reentrancy and thread safety
It's not easy to say I love you | use the minimum web API to upload files (swagger support) # yyds dry inventory #
SimpleITK使用——4. 奇怪的問題
【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
UE4 游戏架构 学习笔记
U++ learning notes - relaxation
SimpleITK使用——3. 常见操作
go 多线程数据搜索
性能优化----严苛模式
服务器响应状态码