Skip to content

Commit 1eaf187

Browse files
authored
Create solution.cpp
1 parent b43e1e0 commit 1eaf187

File tree

1 file changed

+13
-0
lines changed
  • 1790.仅执行一次字符串交换能否使两个字符串相等

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
bool areAlmostEqual(string s1, string s2) {
4+
vector<int> vec;
5+
int sz=s1.size();
6+
for (int i=0;i<sz;i++) {
7+
if (s1.at(i)!=s2.at(i)) {
8+
vec.push_back(i);
9+
}
10+
}
11+
return vec.size()==0 || (vec.size()==2 && s1.at(vec.at(0))==s2.at(vec.at(1)) && s1.at(vec.at(1))==s2.at(vec.at(0)));
12+
}
13+
};

0 commit comments

Comments
 (0)