当前位置:网站首页>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) # 4
Knowledge points involved :
[Python] sort() Method VS sorted() function https://blog.csdn.net/Hudas/article/details/122884550
边栏推荐
- 大话云原生之负载均衡篇-小饭馆客流量变大了
- Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
- go 条件变量
- Oracle-PL/SQL编程
- Phpcms realizes the direct Alipay payment function of orders
- SimpleITK使用——3. 常见操作
- go 4種單例模式
- U++ 学习笔记 ----松弛
- Mathematical modeling -- graph and network models and methods (I)
- 手写ORM(对象关系映射)增删改查
猜你喜欢
Task and privilege level protection
NC24325 [USACO 2012 Mar S]Flowerpot
[foreign journal] sleep and weight loss
Radis:Linux上安装Redis(步骤)
Mathematical modeling -- graph and network models and methods (I)
Simpleitk use - 3 Common operations
SimpleITK使用——3. 常见操作
悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
牛客网:最大子矩阵
Dynamic memory allocation (malloc calloc realloc free)
随机推荐
大一学习分享
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
P7072 [CSP-J2020] 直播获奖
手写ORM(对象关系映射)增删改查
Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
How should programmers write logs
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
杰理之直接触摸样机的顶针反应不正常【篇】
[QT] QT multithreading development - four methods to realize multithreading design
How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
JS solution for obtaining the width and height of hidden elements whose display is none
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
Socket socket c/s end process
牛客网:最大子矩阵
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
[LeetCode] 反转字符串【344】
Task and privilege level protection
I admire that someone explained such an obscure subject as advanced mathematics so easily
对象与对象变量