Kth Largest Element in an Array - LeetCode
examination questions
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
For example,
Given [3,2,1,5,6,4]
and k = 2, return 5.
Note:
You may assume k is always valid, 1 ≤ k ≤ array's length.
Please use the following function to solve the problem:
int findKthLargest(int* nums, int numsSize, int k) {
}
解法1:选择排序
解题代码
int findKthLargest(int* nums, int numsSize, int k) { int temp;
for (int i = ; i < numsSize-; i++){
for (int j = i+; j < numsSize; j++){
if (nums[i]> nums[j]){
temp = nums[j];
nums[j] = nums[i];
nums[i] = temp;
}
}
}
return nums[numsSize - k]; }
LeetCode判断结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABIoAAAChCAIAAAAnV8NEAAAVnklEQVR4nO3dz2scV4IH8P2f6tTIwujiIQkZsAlr6MwhhsDg5GAWG1tJJgoxOyRgHwKaMWFjHOEFs8FjsNebgYnAQXiGJQbHDGIChmTksBh80E2XvojeQ1V3v/rVVdVqu5+jz4cc0t2vXr36IXhfv1ev/mUIAABABP5l0Q0AAABgOBTPAAAAIiGeAQAAREE8AwAAiIJ4RpW9vb1FNwEAAA6bWeLZ3vbd9fdPHT+23EuSJEmSpZVX+qcvXb//46w9+jvnkiRJ3lj/+4zbt/H39TeSJEnO3XlJ6m2z05Le8rHjp95fv7t9kGy1t33zgxNLMx1Q8UK+iAsLAAC/GF3j2eDhlTeXKqNBkiQrb197OJihEeLZbDutt/Tm5a2nM1aeXg3xDAAAXrRu8Wz369WVNIddvvvg590siu09275/ffXXvSRJkpXVr3c7N0IvvqM0npVO2GD35+371z84sZQkSdI7uT5TVj5IPKuuyoUFAIBWOsWz3RunkyRJ3visqt8/+OunryVJkvzmi8ddG6EX31FNPMsMntw6tzL7GRXPAABgMTrFs4aJfKWf68rXzoEb/HDr4qlXl5IkSZZW+meLD1FNyj25t/7O68u9JEl6y6+/s55O5Ct+e+9JkCIr2vL0u+sXT72ePUG3tHL81MWbpYe2GstUH+Pe9s2Lp46vLNV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AHNId4BgAAwPMjngEAAERBPAMAAIiCeAYAABAF8QwAACAK4hkAAEAUxDMAAIAoiGcAAABREM8AAACiIJ4BAABEQTwDAACIgngGAAAQBfEMAAAgCuIZAABAFMQzAACAKIhnAAAAUfh/2UlqPILdbfsAAAAASUVORK5CYII=" alt="" />
解法2:插入排序
解题代码
int findKthLargest(int* nums, int numsSize, int k) { int *tempArray = (int *)malloc(sizeof(int)*numsSize);
memset(tempArray,,sizeof(int)*numsSize); for (int i = ; i < numsSize; i++){
for (int j = ; j < numsSize; j++){
if (nums[i]>tempArray[j]){
int b = numsSize - j;
for (int t = ; t <= b; t++){
tempArray[numsSize-t] = tempArray[numsSize-t-];
}
tempArray[j] = nums[i];
break;
}
}
}
return tempArray[k-];
}
LeetCode判断结果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABJcAAACACAIAAAA59x+PAAASsUlEQVR4nO3dPW8bV6KA4fyJ/SVxsbiloB+QAO6dwJ3durM7N25SOcEGAtJdYOEigeWFbxGkCOI4bryOKTGzIikzKhwjEKkQIhXL4IbWLUiR80kOPyRypOfFW8jD4eEhXb04Z2Y+OAEAAAAAFIcPlj0BAAAAAMAUqDgAAAAAKBIqDlh1ut1us9nc29ur1WpBEJRKpZ+RRqlUCoKgVqvt7e01m81ut7vs/zoAAIAzQcUBK0qv12s0GtVqtVQq9bOk0+m8e/eu1+ste2orSq/XOz4+7nQ6/egtlUrVarXRaLx//37ZUwMAAFgkKg5YRQ4ODoIgqNfr7XZbts1Gr9drt9v1ej0Igj/++GPZ0wEAAFgYKg5YLbrdbqVSqdVqnU5n2XO5IHQ6nVqtVqlU7LEEAAAXAxUHrBBHR0flcrnRaCx7IheQ/f39crl8dHS07IkAAADMi4oDVoVWq7W1tXV4eLjsiVxYDg8Pt7a2Wq3WsicCAAAwFyoOWAmOjo62trasFJ01x8fHfmcAAFB0VBywfLrdbrlctgp3PhweHpbLZdfIAQCA4qLigOVTqVRcC3ee7O/vVyqVZc8CAABgRlQc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SJMkiqeJIkiRJskiqOJIkSZIskudacc0XW4e7r5b+nUmSJEmyoB7uvmr+vH1+FdcKKq1gZ+lfmyRJkiQLaivYaQWV86u4//75tvHvrdYvO1bkSJIkSXIqD3dftYKdxr+3ukdH51dx/ZBrBZXmi63G8xJJkiRJMqfNF9utoLKohJui4gAAAAAAq4CKAwAAAIAioeIAAAAAoEioOAAAAAAoEioOAAAAAIqEigMAAACAIqHiAAAAAKBIqDgAAAAAKBIqDgAAAACKhIoDAAAAgCKh4gAAAACgSKg4AAAAACgSKg4AAAAAioSKAwAAAIAioeIAAAAAoEj8P9xFVsKOVXJmAAAAAElFTkSuQmCC" alt="" />
不知为何会出现这样的错误?代码在本机测试正常。
其他算法分析有时间再添加。
Kth Largest Element in an Array - LeetCode的更多相关文章
- leetcode面试准备:Kth Largest Element in an Array
leetcode面试准备:Kth Largest Element in an Array 1 题目 Find the kth largest element in an unsorted array. ...
- 剑指offer 最小的k个数 、 leetcode 215. Kth Largest Element in an Array 、295. Find Median from Data Stream(剑指 数据流中位数)
注意multiset的一个bug: multiset带一个参数的erase函数原型有两种.一是传递一个元素值,如上面例子代码中,这时候删除的是集合中所有值等于输入值的元素,并且返回删除的元素个数:另外 ...
- Leetcode 之 Kth Largest Element in an Array
636.Kth Largest Element in an Array 1.Problem Find the kth largest element in an unsorted array. Not ...
- [Leetcode Week11]Kth Largest Element in an Array
Kth Largest Element in an Array 题解 题目来源:https://leetcode.com/problems/kth-largest-element-in-an-arra ...
- 网易2016 实习研发工程师 [编程题]寻找第K大 and leetcode 215. Kth Largest Element in an Array
传送门 有一个整数数组,请你根据快速排序的思路,找出数组中第K大的数. 给定一个整数数组a,同时给定它的大小n和要找的K(K在1到n之间),请返回第K大的数,保证答案存在. 测试样例: [1,3,5, ...
- LeetCode OJ 215. Kth Largest Element in an Array 堆排序求解
题目链接:https://leetcode.com/problems/kth-largest-element-in-an-array/ 215. Kth Largest Element in an A ...
- 【LeetCode】215. Kth Largest Element in an Array (2 solutions)
Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is t ...
- LN : leetcode 215 Kth Largest Element in an Array
lc 215 Kth Largest Element in an Array 215 Kth Largest Element in an Array Find the kth largest elem ...
- 【刷题-LeetCode】215. Kth Largest Element in an Array
Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is t ...
随机推荐
- [译]line clampin让文字在指定的行数内省略号显示
说明 (1)原文:http://css-tricks.com/line-clampin/ (2)非直译 需求: 当文字长度超过N行时,文字后面自动用省略号补齐. 比如,你有如下的HTML代码: < ...
- 全局方法&Number对象
//js端 function println(string){ document.write(string+"<br/>"); } //html端 <script ...
- Range
欢迎转载,转载请注明出处,徽沪一郎. 概要 Scala中Range可以看成是List的特例,Range的包含的元素类型是Int, 本文介绍如何创建Range Range创建 方法一: val r1 = ...
- gdb调试,自动显示多个变量的值
调试程序的时候有时候要一行监控多个变量的值, 可以这样写: p {var1, var2, var3} 要跟踪程序自动显示,可以使用display display {var1, var2, var3}要 ...
- vmware centos6.5 net 配置
使用NAT模式 虚拟机网络连接使用NAT模式,物理机网络连接使用Vmnet8. 虚拟机设置里面——网络适配器,网络连接选择NAT模式. 虚拟机菜单栏—编辑—虚拟网络编辑器,选择Vmnet8 NAT模式 ...
- HAProxy 实践(一)
运行环境 OS: Deiban 7 软件:haproxy 1.5.8 HTTP Server: 192.168.99.1:8520 192.168.99.1:8530 192.168.99.1:854 ...
- HTML其他基本格式说明
1.<!DOCTYPE>说明页面中使用的HTML版本,只是信息声明 2.元信息元素<meta>,通过属性定义文件信息的名称.内容.文档的关键字.作者及描述等..content内 ...
- 关联分析---Apriori
关联分析是一种在大规模数据集中寻找有趣关系的任务,这些关系有两种形式:频繁项集和关联规则.频繁项集是经常出现在一起的物品的集合,关联规则暗示两种物品之间可能存在的很强的关系. 如何寻找数据集中的频繁或 ...
- sublimetext ruby 插件
写ruby的编辑器推荐 俗话说磨刀不误砍柴工,好的编辑器可以写的更舒服,更快. 完全初学者建议用RubyMine,这个目前估计最强的写Ruby的IDE. 不过我没有使用它,因为它速度太慢了.如果你能 ...
- 变量在SSIS包中的使用
2010~2011年经常使用SSIS包采集加工数据,后来换了工作就很少使用.最近又开始用那玩意采集数据,努力回想之前是怎样操作的,网上各种找各种纠结.趁这次使用记录下日常操作步骤,以备以后不时之需. ...