二次排序LincodeNo.846

846.Multi-keyword Sort

题目要求在已经排序好的序列上进行二次排序

那么改变一下比较方法即可

bool cmp(vector<int> a,vector<int> b)
{
    if(a[1]==b[1])
        return a[0]<b[0];
    return a[1]>b[1];

}
class Solution {
public:
    /**
     * @param array: the input array
     * @return: the sorted array
     */

    vector<vector<int>> multiSort(vector<vector<int>> &array)
    {
        // Write your code here
        sort(array.begin(),array.end(),cmp);
        return array;
        
    }
};

如果用实现C语言也是同样的做法,改变的是 比较两个元素的比较方法

以后再要自己写排序的话再补充上C语言的代码

猜你喜欢

转载自www.cnblogs.com/virgildevil/p/11824259.html