leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1337.cpp (628B)
0 class Solution { 1 public: 2 typedef pair<int, int> ii; 3 vector<int> kWeakestRows(vector<vector<int>> &mat, int k) { 4 vector<ii> vp; 5 6 int i = 0; 7 for (auto &v : mat) 8 vp.push_back(make_pair(i++, accumulate(v.begin(), v.end(), 0))); 9 10 sort(vp.begin(), vp.end(), [](const ii &a, const ii &b) -> bool { 11 return a.second < b.second || (a.second == b.second && a.first < b.first); 12 }); 13 14 vector<int> res; 15 for (auto &p : vp) 16 if (k--) 17 res.push_back(p.first); 18 else 19 break; 20 21 return res; 22 } 23 };