【Leetcode_easy】859. Buddy Strings
problem
solution:
class Solution { public: bool buddyStrings(string A, string B) { if(A.size()!=B.size()) return false; if(A==B && unordered_set<char>(A.begin(), A.end()).size()<A.size()) return true; vector<int> diff; for(int i=0; i<A.size(); ++i) { if(A[i]!=B[i]) diff.push_back(i); } return diff.size()==2 && A[diff[0]]==B[diff[1]] && A[diff[1]]==B[diff[0]]; } };
参考
1. Leetcode_easy_859. Buddy Strings;
2. grandyang;
3. Discuss;
完
各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/