JZ32 把数组排成最小的数
本文最后更新于:2022年4月9日 中午
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public: string PrintMinNumber(vector<int> numbers) { vector<string> record; for (int num : numbers) { record.push_back(to_string(num)); } auto cmp = [](string& lhs, string& rhs) { return lhs+rhs < rhs+lhs; }; sort(record.begin(), record.end(), cmp); string ss; for (string& s : record) { ss += s; } return ss; } };
|