C++ 大佬帮帮我:sort自定义compare函数引发了异常
如果sort使用myCompare程序正常运行,而使用mc会报:将一个无效参数传递给了将无效参数视为严重错误的函数异常。
这是为什么,&如何debug这种错误找到问题所在?
class Solution1 {
static bool myCompare(string x, string y) {//降序
return x + y > y + x;
}
static bool mc(string x, string y) {
return (x + y).compare(y + x);
}
string largestNumber(vector<int>& nums) {
vector<string> numStr;
string max;
for (auto iter = nums.begin(); iter != nums.end(); iter++)
numStr.push_back(to_string(*iter));
sort(numStr.begin(), numStr.end(), myCompare);//这里报错了!!!!!
for (auto a : numStr) {
max += a;
}
if (max[0] == '0')return "0";
return max;
}
};