LeetCode题解之Largest Number

1、题目描述

2、 将整数值转换为string  ,然后排序。

3、代码

 1 string largestNumber(vector<int>& nums) {
 2         vector<string> s;
 3         for( auto n : nums){
 4             s.push_back(to_string(n));
 5         }
 6         
 7         sort( begin(s), end(s) , [](string &s1 , string s2){ return s1 + s2 < s2 + s1;});
 8         string res ; 
 9         for(vector<string>::reverse_iterator it = s.rbegin() ; it != s.rend(); ++it){
10             res += *it;
11         }
12         if( res.front() == '0')
13             res = "0";
14         return res;
15         
16     }
pp
原文地址:https://www.cnblogs.com/wangxiaoyong/p/9570912.html