<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 {
private:
    struct digits_cmp {
        bool operator()(int e1, int e2) const {
            unsigned long long pow;
            unsigned long long val1, val2;

            for (pow = 10; e2 / pow > 0; pow *= 10)
                ;
            val1 = e1 * pow + e2;

            for (pow = 10; e1 / pow > 0; pow *= 10)
                ;
            val2 = e2 * pow + e1;

            return val1 > val2;
        }
    };

public:
    string largestNumber(vector<int>& nums) {
        int i, n;
        string res;
        struct digits_cmp cmp;

        sort(begin(nums), end(nums), cmp);

        n = nums.size();

        for (i = 0; i < n; i++) {
            int val = nums[i];
            unsigned long long pow;

            for (pow = 10; val / pow > 0; pow *= 10)
                ;
            pow /= 10;

            for (;;) {
                res += '0' + val / pow % 10;
                if (pow == 1)
                    break;
                pow /= 10;
            }
        }

        if (res[0] == '0')
            res.resize(1);

        return res;
    }
};
13200