class Solution {
public:
int findKthLargest(vector<int>& nums, int k) {
sort(nums.begin(), nums.end());
return nums[nums.size() - k];
}
};

补充python的实现,使用堆排序:

 import heapq
class Solution:
def findKthLargest(self, nums: 'List[int]', k: 'int') -> 'int':
lists = heapq.nlargest(k,nums)
return lists[-]

leetcode215的更多相关文章

  1. [Swift]LeetCode215. 数组中的第K个最大元素 | Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  2. LeetCode215. 数组中的第K个最大元素

    215. 数组中的第K个最大元素 问题描述 在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 示例 示例 1: 输入: [3 ...

  3. LeetCode215:Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  4. tusen 刷题

    //1.single number和变体 //2.lru lfu 3.给一个正整数集合,求一个和最大且能被3整除的子集.Follow up: 如果集合里有正有负 4.leetcode200-numbe ...

  5. Leetcode Note

    算法刷题笔记 Leetcode-11. Container With Most Water Method: (对撞指针)每次保留两指针中最大的那个即可求得最大的面积 Runtime: 16 ms, f ...

  6. 215. 数组中的第K个最大元素 + 快速排序 + 大根堆

    215. 数组中的第K个最大元素 LeetCode-215 另一道类似的第k大元素问题:https://www.cnblogs.com/GarrettWale/p/14386862.html 题目详情 ...

随机推荐

  1. Ubuntu虚拟机屏幕自适应与文件拖拽复制方法

    使用VMware-tools的替代品:open-vm-tools 安装步骤: 1 更新下系统源 sudo apt update 2 安装open-vm-tools sudo apt install o ...

  2. 分布式队列celery 异步----Django框架中的使用

    仅仅是个人学习的过程,发现有问题欢迎留言 一.celery 介绍 celery是一种功能完备的即插即用的任务对列 celery适用异步处理问题,比如上传邮件.上传文件.图像处理等比较耗时的事情 异步执 ...

  3. SQLserver触发器实现A表insert到B表

    CREATE TABLE tab1(tab1_id varchar(11));CREATE TABLE tab2(tab2_id varchar(11)); 现在我们有两张表,要实现在A表里面inse ...

  4. requests模块的使用

    requests模块 什么是request模块:requests是python原生一个基于网络请求的模块,模拟浏览器发起请求. requests-get请求 # get请求 import reques ...

  5. Python全栈之路----常用模块----random模块

    程序中有很多地方需要用到随机字符,比如登陆网站的随机验证码,通过random模块可以很容易生成随机字符串. >>> import random >>> random ...

  6. PHP常见错误级别及错误码

    数字 常量 说明 1 E_ERROR 致命错误,脚本执行中断,就是脚本中有不可识别的东西出现 举例: Error:Invalid parameters. Invalid parameter name ...

  7. 《从Lucene到Elasticsearch:全文检索实战》学习笔记四

    今天我给大家讲讲布尔检索模型基本概念 布尔检索模型: 检索模型是判断文档内容与用户相关性的核心技术,以大规模网页搜索为例,在海量网页中与用户查询关键词相关的网页可能会有成千上万个,甚至耕读哦.那么信息 ...

  8. 我的代码-cleaning

    # coding: utf-8 # In[18]: import pandas as pdimport numpy as npfrom sklearn import treefrom sklearn. ...

  9. Arch Linux root密码忘记了怎么办

    https://wiki.archlinux.org/index.php/Reset_root_password_(简体中文)https://wiki.archlinux.org/index.php/ ...

  10. 基于tensorflow的逻辑分类

    #!/usr/local/bin/python3 ##ljj [2] ##logic classify model import tensorflow as tf import matplotlib. ...