把数组排成最小的树

 1 class Solution {
 2 public:
 3     string PrintMinNumber(vector<int> numbers) {
 4         string res;
 5         if(numbers.size()==0) return res;
 6         sort(numbers.begin(),numbers.end(),cmp);
 7         for(int i=0;i<numbers.size();i++){
 8             res+=to_string(numbers[i]);
 9         }
10         return res;
11     }
12     static bool cmp(int a,int b){
13         string str1 = to_string(a);
14         string str2 = to_string(b);
15         return str1+str2 < str2+str1;
16     }
17 };

 

posted @ 2019-07-10 16:08  Austin_anheqiao  阅读(214)  评论(0编辑  收藏  举报