<p>Given a list of non-negative integers <code>nums</code>, arrange them such that they form the largest number and return it.</p>

<p>Since the result may be very large, so you need to return a string instead of an integer.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [10,2]
<strong>Output:</strong> &quot;210&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,30,34,5,9]
<strong>Output:</strong> &quot;9534330&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 100</code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution {
public:
    static bool compare(const string& a, const string& b) {
        const auto len1 = a.length(), len2 = b.length(), mx = lcm(len1, len2);
        for (size_t i = 0; i < mx; i++)
            if (const char c1 = a[i % len1], c2 = b[i % len2]; c1 != c2)
                return c1 > c2;
        return false;
    }

    string largestNumber(const vector<int>& nums) {
        vector<string> s; s.reserve(nums.size());
        for (const auto& x : nums)
            s.push_back(to_string(x));
        ranges::sort(s, compare);
        return s[0][0] != '0' ? accumulate(s.begin(), s.end(), string{}) : "0";
    }
};
15400