leetcode 215 Kth Largest Element in an Array C++
来源:互联网 发布:mac壁纸怎么设置 编辑:程序博客网 时间:2024/06/11 21:15
帮别人找bug,顺便把这道题做了,用的是快排的方式。
int findKLargestElement(int k, vector<int>& nums, int low, int high) { int left = low; int right = high; int key = nums[left]; while (left < right) { while (left < right && nums[right] < key) --right; nums[left] = nums[right]; while (left < right && nums[left] >= key) ++left; nums[right] = nums[left]; } nums[left] = key; if (left < (k-1)) { return findKLargestElement(k, nums, left+1, high); } else if (left > (k-1)) { return findKLargestElement(k, nums, low, left-1); } else { return key; } } int findKthLargest(vector<int>& nums, int k) { return findKLargestElement(k, nums, 0, nums.size()-1); }
0 0
- Leetcode Kth Largest Element in an Array
- Leetcode: Kth Largest Element in an Array
- LeetCode Kth Largest Element in an Array
- [LeetCode] Kth Largest Element in an Array
- [leetcode] Kth Largest Element in an Array
- leetcode--Kth Largest Element in an Array
- #leetcode#Kth Largest Element in an Array
- LeetCode Kth Largest Element in an Array
- 【Leetcode】Kth Largest Element in an Array
- Leetcode: Kth Largest Element in an Array
- Kth Largest Element in an Array -- leetcode
- [Leetcode]Kth Largest Element in an Array
- [LeetCode]Kth Largest Element in an Array
- *LeetCode-Kth Largest Element in an Array
- LeetCode----Kth Largest Element in an Array
- LeetCode Kth Largest Element in an Array
- leetcode-Kth Largest Element in an Array
- LeetCode -- Kth Largest Element in an Array
- 玩玩Linux云主机-Linux下的各个目录,笔者使用cd的时候乱了,所以了解一下子
- Dubbo(一) zookeeper环境的搭建(单节点)
- linux+nginx安装
- 【JavaScript】 Html 引用 JavaScript
- 中科爱讯WiFi探针的功能与应用
- leetcode 215 Kth Largest Element in an Array C++
- 浏览器端的存储技术有哪些
- mnist数字显示 python实现
- .net中的数据访问层的封装
- 关于DEV中的GridControl使用之GridView
- Spring事务管理TransactionManager
- 磁盘性能测试
- Android模拟器中访问局域网地址
- UILabel标签文字过长时的显示方式