题解 | #寻找第K大#
寻找第K大
http://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
# -*- coding:utf-8 -*-
class Solution:
def findKth(self, a, n, K):
# write code here
for i in range(K):
for j in range(len(a)-1-i):
if a[j] > a[j+1]:
a[j],a[j+1] = a[j+1], a[j]
return a[n-K] 采用了冒泡排序法,求第K大的数,排序前K大的数,输出第K位即可。


