目录
一、题目
二、解答
一、题目
LCR 164. 破解闯关密码 - 力扣(LeetCode)

二、解答
- std::stoi返回的是一个- int类型的整数。
- std::stoull返回的是一个- unsigned long long类型的整数(无符号长整数)

 
 
class Solution {
public:
static bool Compare(int a, int b)//判断两个数字拼接以后的大小
{
    string s1 = to_string(a);
    string s2 = to_string(b);
    return stoull(s1 + s2) < stoull(s2 + s1);
}
string crackPassword(vector<int>& password)
{
    sort(password.begin(), password.end(), Compare);
    string retStr;
    for (auto ch : password)
    {
        retStr += to_string(ch);
    }
    return retStr;
}
};

















