leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0179.cpp (497B)


      1 class Solution {
      2   public:
      3     string largestNumber(const vector<int> &nums) {
      4         const static auto cmp = [](const string &x, const string &y) { return x + y > y + x; };
      5 
      6         vector<string> v(nums.size());
      7         for (int i = 0; i < v.size(); i++)
      8             v[i] = to_string(nums[i]);
      9 
     10         sort(v.begin(), v.end(), cmp);
     11         if (v[0] == "0") return "0";
     12 
     13         string res = "";
     14         for (int i = 0; i < v.size(); i++)
     15             res += v[i];
     16         return res;
     17     }
     18 };