string 型默认为“”;它是不能和NULL进行比较的。牛客网上刷这题,居然因为我判断输入为空时,返回NULL,判我死循环!!!
bool comp(string a,string b) { string tmp1,tmp2; tmp1=a+b; tmp2=b+a; return (tmp1<tmp2) ? true: false; } class Solution { public: string inToStr(int n) { char *p=new char[100]; sprintf(p,"%d",n); string s=p; delete []p; return s; } string PrintMinNumber(vector<int> numbers) { string s; if(numbers.empty()) return s; string tmp; vector<string> num; for(int i=0;i<numbers.size();i++) { tmp=inToStr(numbers[i]); num.push_back(tmp); } // if(numbers.size()==1) // return num[0]; sort(num.begin(),num.end(),comp); for(int i=0;i<num.size();i++) s+=num[i]; return s; } };