<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:
    bool compare(string& s1, string& s2){
        return s1+s2 > s2+s1;
    }

    string largestNumber(vector<int>& nums) {
        list<string> ordered;
        for(int n : nums){
            string s = to_string(n);
            auto it = ordered.begin();
            while(it!=ordered.end()){
                if(compare(*it,s)){it++;}
                else{
                    ordered.insert(it, s);
                    break;
                }
            }
            if(it == ordered.end()) ordered.push_back(s);
        }
        if (ordered.front() == "0") return "0";
        string f;
        for(string s : ordered) f += s;
        return f;
    }
};

// class Solution {
// public:
//     string largestNumber(vector<int>& nums) {
//         vector<string> strs;
//         for(int n : nums){
//             strs.push_back(to_string(n) + 'a');
//         }
//         sort(strs.begin(), strs.end());
//         string f;
//         while(strs.size()){
//             string s = strs.back();
//             s.pop_back();
//             f += s;
//         }
//         return f;
//     }
// };
16600