当前位置:网站首页>[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
边栏推荐
- 杰理之修改不需要长按开机功能【篇】
- [error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')
- NC50965 Largest Rectangle in a Histogram
- Oracle PL / SQL programming
- 影视随摘
- Market Research - current situation and future development trend of anterior cruciate ligament (ACL) reconstruction Market
- Regular expression (2)
- SimpleITK使用——4. 奇怪的問題
- Jerry's modification does not require long press the boot function [chapter]
- Market Research - current situation and future development trend of carob chocolate market
猜你喜欢

Pointer and string

Sql service intercepts string

PMP项目整合管理

Simpleitk use - 4 Strange question

phpcms实现订单直接支付宝支付功能

Socket套接字C/S端流程
![[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')](/img/02/67448df1817e8b34b654722df8ecd4.jpg)
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
![NC24325 [USACO 2012 Mar S]Flowerpot](/img/cf/86acbcb524b3af0999ce887c877781.png)
NC24325 [USACO 2012 Mar S]Flowerpot

Struct, bit segment, enumeration, union
随机推荐
[shutter] shutter application theme (themedata | dynamic modification theme)
Pointer array parameter passing, pointer parameter passing
Utilisation de simpletk - 4. Question étrange
Unity3d learning notes 4 - create mesh advanced interface
Mathematical modeling -- graph and network models and methods (I)
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
Market Research - current market situation and future development trend of total nutrition products
Market Research - current market situation and future development trend of handheld wound imaging equipment
杰理之直接触摸样机的顶针反应不正常【篇】
Commodity information management system (C language document version)
影视随摘
PHP微信抢红包的算法
PHP optimizes SQL queries in foreach
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
服务器响应状态码
牛客网:龙与地下城游戏
Regular expression (2)
Hanoi Tower problem
Build your own website (22)