一.题目描述
给一组整数,按照升序排序。使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法。
样例
给出 [3, 2, 1, 4, 5], 排序后的结果为 [1, 2, 3, 4, 5]。
二.解题思路
sort函数就是时间复杂度为O(nlogn)的算法,用sort函数进行排序.
三.实现代码
class Solution { public: /** * @param A an integer array * @return void */ void sortIntegers2(vector<int>& A) { // Write your code here if(A.size()!=0) sort(A.begin(),A.end()); } };
四.感想
此题利用sort函数比较简单.