先准备两个数组,存放所有数据;对一个数组从大到小排序,取出第n大和第m大的数;在未排序的数组查找这两个数,并交换位置。
运行时间:32ms 占用内存:6524KB 使用语言:Python 3 用例通过率:100.00%
class Solution:
def sovle(self, a, n, m):
o = sorted(a, reverse=True)
idx1 = a.index(o[n-1])
idx2 = a.index(o[m-1])
a[idx1], a[idx2] = a[idx2], a[idx1]
return a


京公网安备 11010502036488号