LeetCode题解之Largest Number
生活随笔
收集整理的這篇文章主要介紹了
LeetCode题解之Largest Number
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、題目描述
?
2、 將整數(shù)值轉(zhuǎn)換為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 }?
轉(zhuǎn)載于:https://www.cnblogs.com/wangxiaoyong/p/9570912.html
總結(jié)
以上是生活随笔為你收集整理的LeetCode题解之Largest Number的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeforces 1029 A. M
- 下一篇: Redis学习笔记(八)——持久化