剑指offer---把数组排成最小的数

//弄成字符串比较 稍易
class Solution 
{
public:
    static bool compare(const string &a, const string &b)
    {
        string s1 = (a + b);
        string s2 = (b + a);
        return s1 < s2;
    }
    string PrintMinNumber(vector<int> numbers) 
    {
        string result;
        if (numbers.size() <= 0) return result;

        vector<string> re;
        int in_size = numbers.size();
    
        for (int i = 0; i < in_size; ++i)
        {
            stringstream ss;
            ss << numbers[i];
            string A = ss.str();
            re.push_back(A);
        }

        sort(re.begin(), re.end(), compare);

        for (int i = 0; i < re.size(); ++i)
        {
            result = result + re[i];
        }

        return result;


    }
};

 

posted @ 2017-08-03 21:34  双马尾是老公的方向盘  阅读(98)  评论(0编辑  收藏  举报