当前位置:网站首页>数组中的第K个最大元素
数组中的第K个最大元素
2022-07-04 17:39:00 【charlsdm】
- 数组中的第K个最大元素
给定整数数组 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
我的C#AC代码` public partial class Solution
{
public int FindKthLargest(int[] nums, int k)
{
List<int> mynums = nums.ToList();
mynums.Sort();
mynums.Reverse();
return mynums[k-1];
}
}
边栏推荐
- 基于C语言的菜鸟驿站管理系统
- Halcon template matching
- 使用SSH
- Perfect JS event delegation
- 启牛开的证券账户安全吗?
- How is the entered query SQL statement executed?
- Li Chi's work and life summary in June 2022
- Scala basic tutorial -- 12 -- Reading and writing data
- Journal des problèmes de brosse à boutons de force / day6 / 6.28
- 6.26CF模拟赛B:数组缩减题解
猜你喜欢
每日一题(2022-07-02)——最低加油次数
Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
Angry bird design based on unity
Li Kou brush question diary /day7/6.30
DeFi生态NFT流动性挖矿系统开发搭建
Nebula Importer 数据导入实践
How is the entered query SQL statement executed?
Li Kou brush question diary /day5/2022.6.27
Scala basic tutorial -- 18 -- set (2)
随机推荐
2022养生展,健康展,北京大健康展,健康产业展11月举办
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
力扣刷题日记/day7/6.30
2022 ByteDance daily practice experience (Tiktok)
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
Li Kou brush question diary /day7/6.30
【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
Li Kou brush question diary /day5/2022.6.27
6.26CF模拟赛E:价格最大化题解
SSL证书续费相关问题详解
一、C语言入门基础
奥迪AUDI EDI INVOIC发票报文详解
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
Pb extended DLL development (super chapter) (VII)
What types of Thawte wildcard SSL certificates provide
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
力扣刷题日记/day3/2022.6.25
1、 Introduction to C language
2022健康展,北京健博会,中国健康展,大健康展11月13日