title: Largest Number from leetcode : can someone explain why this method works?
body: <p>Here's <a href="https://oj.leetcode.com/problems/largest-number/" rel="nofollow">the question from leetcode</a></p>
  
  <blockquote>
    <p>Given a list of non negative integers, arrange them such that they
    form the largest number.</p>
    
    <p>For example, given [3, 30, 34, 5, 9], the largest formed number is
    9534330.</p>
  </blockquote>
  
  <p>Here's the simplest solution I've ever seen:</p>
  
  <pre><code>class Solution {
  public:
      string largestNumber(vector&lt;int&gt; &amp;num) {
          vector&lt;string&gt; arr;
          for(auto i:num)
              arr.push_back(to_string(i));
          sort(begin(arr), end(arr), [](string &amp;s1, string &amp;s2){ return s1+s2&gt;s2+s1; });
          string res;
          for(auto s:arr)
              res+=s;
          while(res[0]=='0' &amp;&amp; res.length()&gt;1)
              res.erase(0,1);
          return  res;
      }
  };
  </code></pre>
  
  <p>I am so confused that why this method works..Could anybody give a prove to this method?</p>