<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 customSort(const int &a, const int &b) {
        if (a==0) return false;
        if (b==0) return true;
        int x = log10(a);
        int y = log10(b);
        unsigned long long p=a, q=b;
        p = p * (unsigned long long)pow(10, y+1) + b;
        q = q * (unsigned long long)pow(10, x+1) + a;
        // cout << "input = " << a << " " << b << endl;
        // cout << "comp = " << p << " " << q << endl;
        return p > q;
    }
    string largestNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end(), customSort);
        string ans = "";
        int x, p;
        for (int n:nums) {
            if (n==0) {
                if (ans.size()) ans += '0';
                continue;
            }
            x = log10(n)+1;
            while(x--) {
                p = (int)pow(10, x);
                ans += (n/p) + '0';
                n = n % p;
            }
        }
        return ans.size() ? ans:"0";
    }
};
13800