LeetCode-Solutions-in-Cpp17

Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.


Project maintained by downdemo Hosted on GitHub Pages — Theme by mattgraham
class Solution {
 public:
  string largestNumber(vector<int>& nums) {
    if (all_of(begin(nums), end(nums), [](int x) { return !x; })) {
      return "0";
    }
    vector<string> v;
    transform(begin(nums), end(nums), back_inserter(v),
              [](int x) { return to_string(x); });
    sort(begin(v), end(v),
         [](const string& x, const string& y) { return y + x < x + y; });
    return accumulate(begin(v), end(v), string{""});
  }
};