当前位置:网站首页>[LeetCode] 数组中的第K个最大元素【215】
[LeetCode] 数组中的第K个最大元素【215】
2022-07-02 22:06:00 【山茶花开时。】
问题: 给定整数数组nums和整数k,请返回数组中第k个最大的元素
请注意,你需要找的是数组排序后的第k个最大的元素,而不是第k个不同的元素
示例1
输入: [3,2,1,5,6,4] 和 k = 2
输出: 5
示例2
输入: [3,2,3,1,2,4,5,5,6] 和 k = 4
输出: 4
python3解题
# 解法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
涉及知识点:
[Python] sort()方法 VS sorted()函数https://blog.csdn.net/Hudas/article/details/122884550
边栏推荐
- Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
- Oracle-PL/SQL编程
- Objects and object variables
- Socket套接字C/S端流程
- Leetcode circular linked list (fast and slow pointer) code line by line interpretation
- NC50965 Largest Rectangle in a Histogram
- 【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
- 电商系统微服务架构
- SimpleITK使用——3. 常见操作
- Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
猜你喜欢
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
Socket socket c/s end process
Sql service intercepts string
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
Micro service gateway selection, please accept my knees!
Mathematical modeling -- graph and network models and methods (I)
Oracle PL / SQL programming
Build your own website (22)
图形视图框架
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
随机推荐
Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]
Additional: [login information storage] and [login status verification]; (including: summarizing all the contents of [login information storage] and [login status verification] so far;)
杰理之充电拔出,无法触摸开机【篇】
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
Oracle PL / SQL programming
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed
Kubernetes resource object introduction and common commands (4)
Market Research - current market situation and future development trend of genome editing mutation detection kit
佩服,竟然有人把高等数学这么晦涩难懂的科目,讲解得如此通俗易懂
Film and television excerpts
Pointer and string
Simpleitk use - 4 Strange question
杰理之如何测试按键的误触率【篇】
Socket套接字C/S端流程
Learn computer knowledge from scratch
《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
Promise optimized callback hell
Unity publishes a method of webgl playing sound