diff --git a/cpp/2203/220327.cpp b/cpp/2203/220327.cpp index d1a5958..1fca45a 100644 --- a/cpp/2203/220327.cpp +++ b/cpp/2203/220327.cpp @@ -14,6 +14,20 @@ */ class Solution { +public: + static std::vector kWeakestRows(const std::vector>& mat, int k) { + int n = mat.size(); + std::vector idMat(n), ret(n); + for (int i = 0; i < n; ++i) + idMat[ret[i] = i] = std::distance(mat[i].begin(), std::lower_bound(mat[i].begin(), mat[i].end(), 0, std::greater<>())); + std::sort(ret.begin(), ret.end(), [&](int x, int y) { + return idMat[x] == idMat[y] ? x < y : idMat[x] < idMat[y]; + }); + return {ret.begin(), ret.begin() + k}; + } +}; + +class SolutionOld { public: static std::vector kWeakestRows(const std::vector>& mat, int k) { int n = mat.size();