Check if One String Swap Can Make Strings Equal
unknown
c_cpp
10 months ago
458 B
13
Indexable
class Solution {
public:
bool areAlmostEqual(string s1, string s2) {
if (s1 == s2)
return true;
for (int i = 0; i < s1.size() - 1; i++) {
for (int j = i + 1; j < s1.size(); j++) {
swap(s1[i], s1[j]);
if (s1 == s2)
return true;
else
swap(s1[i], s1[j]);
}
}
return false;
}
};Editor is loading...
Leave a Comment