We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
错误题目 : 精选力扣300+题目之字符串 Easy 859. 亲密字符串 具体内容 : 第二版参考答案
bool buddyStrings(string A, string B) { if (A.size() != B.size() || A.size() < 2) return false; int len = A.size(); vector<int> res; res.reserve(len); for (int i = 0; i < len; ++i) { if (A[i] != B[i]) { res.push_back(i); if (res.size() > 2) return false; } } if (res.size() == 0) { unordered_set<char> misMatch(A.begin(), A.end()); return misMatch.size() < len; } return A[res[0]] == B[res[1]] && A[res[1]] == B[res[0]]; }
测试用例"abcb"和"abcd"当res.size()为1时,缺少判断return false导致res[1]报错,故应添加一行代码如下: if (res.size() == 1) return false;
"abcb"
"abcd"
res.size()
1
return false
res[1]
if (res.size() == 1) return false;
The text was updated successfully, but these errors were encountered:
赞!很细心,已经补充,感谢~
Sorry, something went wrong.
No branches or pull requests
错误题目 : 精选力扣300+题目之字符串 Easy 859. 亲密字符串
具体内容 : 第二版参考答案
测试用例
"abcb"
和"abcd"
当res.size()
为1
时,缺少判断return false
导致res[1]
报错,故应添加一行代码如下:if (res.size() == 1) return false;
The text was updated successfully, but these errors were encountered: