剑指OFFER----面试题45. 把数组排成最小的数
链接:https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/
代码:
class Solution { public: static bool cmp(int a, int b) { auto as = to_string(a), bs = to_string(b); return as + bs < bs + as; } string minNumber(vector<int>& nums) { sort(nums.begin(), nums.end(), cmp); string res = ""; for (auto x: nums) res += to_string(x); return res; } };