<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:
    unsigned long long getPowerOf10(unsigned long long x) {
        unsigned long long ans = 1;
        while (x--)
            ans *= 10;
        return ans;
    }
    string largestNumber(vector<int>& nums) {
        int n = nums.size();
        vector<pair<unsigned long long, unsigned long long>> vp;
        unsigned long long temp, exp;
        for (long long num : nums) {
            temp = num;
            exp = 0;
            do {
                exp++;
                temp /= 10;
            } while (temp);
            vp.push_back({num, exp});
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (vp[i].first * getPowerOf10(vp[j].second) + vp[j].first <
                    vp[j].first * getPowerOf10(vp[i].second) + vp[i].first) {
                    swap(vp[i], vp[j]);
                }
            }
        }
        string ans = "";
        for (auto it : vp) {
            ans += to_string(it.first);
        }
        bool allZeroes = true;
        for(char ch:ans){
            if(ch!='0'){
                allZeroes = false;
                break;
            } 
        }

        if(allZeroes) return "0";
        return ans;
    }
};
14900