题解
拼接所有的字符串产生字典序最小的字符串
http://www.nowcoder.com/questionTerminal/f1f6a1a1b6f6409b944f869dc8fd3381
知识点:
1.sort()
2.cmp函数定义
3.静态构造函数:只执行一次,优先执行静态成员变量,函数体
4.常量引用作为参数
5.解除输入输出绑定,加快速度
static const auto io_sync_off = {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
return nullptr;
}();
class Solution {
public:
/**
*
* @param strs string字符串vector the strings
* @return string字符串
*/
string minString(vector<string>& strs) {
// write code here
sort(strs.begin(),strs.end(),cmp);
string ret;
for(auto & str:strs)
ret+=str;
return ret;
}
static bool cmp(const string& s1,const string& s2){
return s1+s2 <s2+s1;
}//字符串比较大小,从小到大};
阿里云工作强度 667人发布