<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:

    struct
    {
        bool operator()(int a, int b) const { 
            return !is_a_smaller( a,  b); 
        }
    }
    customLess;

    static int get_length(int num) 
    {
        if (num == 0) return 1;
        return (int) ceil(log10(num + 1));
    }

    static int get_digit(int num, int digit) 
    {
        int helper = num / pow(10,get_length(num)-digit);
        return helper % 10;
    }

    static bool is_a_smaller (int a, int b) 
    {
        int a_length = get_length(a);
        int b_length = get_length(b);
        int ac = 1, bc = 1;
        for (int i = 1; i <= a_length + b_length; i++)
        {
            int this_digit_afirst, this_digit_bfirst = 0;
            if (i <= a_length)
                this_digit_afirst = get_digit(a, i);
            else
                this_digit_afirst = get_digit(b, i - a_length);

            if (i <= b_length)
                this_digit_bfirst = get_digit(b, i);
            else
                this_digit_bfirst = get_digit(a, i - b_length);

            if (this_digit_afirst != this_digit_bfirst) return (this_digit_afirst < this_digit_bfirst);
        }

 return true;
    }

    string largestNumber(vector<int>& nums) {
       if (all_of(nums.begin(), nums.end(), [&](int i) { return i == 0; }))
            return "0";
        string res = "";
        sort(nums.begin(), nums.end(), customLess);
        for (int i : nums)
            res += to_string(i);
        return res;
    }
};
14800