标签:int get ring size 函数 print html 剑指offer algorithm
#include<iostream> #include<vector> #include<string> #include<strstream> #include<algorithm> bool compare(const string & num1, const string & num2) { string str1 = num1 + num2; string str2 = num2 + num1; return str1<str2; } class Solution { public: string PrintMinNumber(vector<int> numbers) { string res = ""; int len = numbers.size(); if (len>0) { vector<string> strNumbers(len); for (int i = 0;i < len;i++) { strstream ss; ss << numbers[i]; ss >> strNumbers[i]; } sort(strNumbers.begin(), strNumbers.end(), compare); for (auto e : strNumbers) res += e; } return res; } };
留意C++中sort函数的用法,C中qsort的函数用法参见:http://www.cnblogs.com/CCBB/archive/2010/01/15/1648827.html
标签:int get ring size 函数 print html 剑指offer algorithm
原文地址:http://www.cnblogs.com/vincent93/p/7629924.html