当前位置:网站首页>[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
边栏推荐
- SimpleITK使用——3. 常见操作
- 20220702 how do programmers build knowledge systems?
- Market Research - current market situation and future development trend of total nutrition products
- NC50965 Largest Rectangle in a Histogram
- Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
- Web side defense Guide
- 杰理之充电拔出,无法触摸开机【篇】
- SimpleITK使用——4. 奇怪的问题
- Oracle-游标
- Phpcms realizes the direct Alipay payment function of orders
猜你喜欢

大话云原生之负载均衡篇-小饭馆客流量变大了

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

Socket套接字C/S端流程

【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)

NC50965 Largest Rectangle in a Histogram

Task and privilege level protection
![[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)](/img/4c/c8dae41fc2eb18b5153cf36861fc7d.jpg)
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
![[foreign journal] sleep and weight loss](/img/81/42dcfae19e72a0bc761cb7a40fe5d5.jpg)
[foreign journal] sleep and weight loss

牛客网:龙与地下城游戏
![[001] [arm-cortex-m3/4] internal register](/img/49/a0eceac1a67267216dd9b2566033a1.jpg)
[001] [arm-cortex-m3/4] internal register
随机推荐
Market Research - current situation and future development trend of cell-based seafood market
[C question set] of V
Market Research - current market situation and future development trend of aircraft audio control panel system
Learn computer knowledge from scratch
大话云原生之负载均衡篇-小饭馆客流量变大了
Mathematical modeling -- graph and network models and methods (I)
傑理之修改不需要長按開機功能【篇】
kubernetes 使用主机名将 pod 分配在指定节点上
Market Research - current market situation and future development trend of total nutrition products
Market Research - current situation and future development trend of carob chocolate market
How should programmers write logs
Market Research - current situation and future development trend of herringbone gear Market
Market Research - current market situation and future development trend of handheld wound imaging equipment
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
PMP项目整合管理
Market Research - current market situation and future development trend of third-party data platform
Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
ArrayList analysis 2: pits in ITR, listiterator, and sublist
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
Simpleitk use - 3 Common operations