LeetCode 378. Kth Smallest Element in a Sorted Matrix

class Solution {
public:
    int kthSmallest(vector<vector<int>>& matrix, int k) {
        vector<int> a;
        vector<int>::iterator is;
        vector<vector<int>>::iterator it;
        for(it=matrix.begin();it!=matrix.end();it++)
        {
            for(is=(*it).begin();is!=(*it).end();is++)
            {
                a.push_back(*is);
            }
        }
        sort(a.begin(),a.end());
        return a[k-1];
    }
};

你可能感兴趣的:(LeetCode 378. Kth Smallest Element in a Sorted Matrix)