<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:
    int compare(long long a, long long b) {
        string s1 = to_string(a);
        string s2 = to_string(b);
        string temp1 = s1 + s2;
        string temp2 = s2 + s1;
        int x=0;
        while(x<temp1.length() && x<temp2.length()) {
            if(temp1[x]>temp2[x]) return a;
            else if(temp1[x]<temp2[x]) return b;
            x++;
        }
        return a;
    }
    string largestNumber(vector<int>& nums) {
        vector<int>temp = nums;
        for(int i=1;i<nums.size();i++) {
           int tmp = i;
           for(int j=i-1;j>=0;j--) {
            if(compare(temp[i], temp[j])==temp[i]) {
                tmp = j;
            }
           }
           if(tmp==i) continue;
           else {
               vector<int>temp2 = temp;
               for(int i1=tmp+1;i1<=i;i1++) {
                temp[i1]=temp2[i1-1];
               }
               temp[tmp] = nums[i];
           }
        }
        string ans = "";
        for(int i: temp) {
            string s = to_string(i);
            ans+=s;
        }
        if(ans=="0") return ans;
        if(ans[0]!='0') return ans;

        int i = 0; 
        while (ans[i] == '0') 
           i++; 
        ans.erase(0, i-1); 
        return ans;
    }
};
16900