7.29 技巧|
new出来的节点free/delete tip
lcr164. password
转vector<string>后sort a+b<b+a
单纯的a<b,sort不够
我们就可以想,抽象规则比较a+b
class Solution {
public:
string crackPassword(vector<int>& password) {
vector<string> hand;
for(auto p:password)
{
hand.push_back(to_string(p));
}
sort(hand.begin(),hand.end(),[&](string a,string b)
{
return a+b<b+a;
});
string ret;
for(auto& h:hand)
ret+=h;
return ret;
}
};