当前位置:网站首页>数组中的第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];
}
}
边栏推荐
- 小发猫物联网平台搭建与应用模型
- Don't just learn Oracle and MySQL!
- Mxnet implementation of googlenet (parallel connection network)
- 【uniapp】uniapp开发app在线预览pdf文件
- C语言打印练习
- C language printing exercise
- 《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- 激进技术派 vs 项目保守派的微服务架构之争
- Scala basic tutorial -- 20 -- akka
猜你喜欢
Go微服务(二)——Protobuf详细入门
How is the entered query SQL statement executed?
Wireshark packet capturing TLS protocol bar displays version inconsistency
奥迪AUDI EDI INVOIC发票报文详解
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
Scala基础教程--15--递归
Nebula Importer 数据导入实践
What types of Thawte wildcard SSL certificates provide
My colleagues quietly told me that flying Book notification can still play like this
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
随机推荐
Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)
Scala基础教程--14--隐式转换
Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
Technology sharing | interface testing value and system
请教一下 flinksql中 除了数据统计结果是状态被保存 数据本身也是状态吗
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
Interpretation of SIGMOD '22 hiengine paper
Don't just learn Oracle and MySQL!
[uniapp] uniapp development app online Preview PDF file
力扣刷题日记/day8/7.1
神经网络物联网是什么意思通俗的解释
[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
模板_判断素数_开方 / 六素数法
利用策略模式优化if代码【策略模式】
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
Scala basic tutorial -- 18 -- set (2)
Angry bird design based on unity
2022 ByteDance daily practice experience (Tiktok)
使用FTP
6.26cf simulation race e: solution to the problem of price maximization