目录
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;
-
- }
- };