Skip to content

Commit 99fb004

Browse files
committed
Runtime: 4 ms (Top 41.52%) | Memory: 6.3 MB (Top 21.58%)
1 parent 3fcdcb7 commit 99fb004

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/algorithms/C/Check if One String Swap Can Make Strings Equal/Check if One String Swap Can Make Strings Equal.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// Runtime: 4 ms (Top 41.52%) | Memory: 6.3 MB (Top 21.58%)
12
/*
23
https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/
3-
4+
45
Find the number of positions which are different.
5-
Now the strings can be made equal only if there are 0
6+
Now the strings can be made equal only if there are 0
67
different positions or 2 different positions and there are
78
chars on those positions which when swaped will make the
89
strings equal.
@@ -18,7 +19,7 @@ class Solution {
1819
for(int i = 0; i < s1.size(); i++) {
1920
if(s1[i] != s2[i])
2021
diff_pos.emplace_back(i);
21-
// If there are more than 2 char positions that differ,
22+
// If there are more than 2 char positions that differ,
2223
// the single swap op cannot anyway make the two strings equal
2324
if(diff_pos.size() > 2)
2425
return false;
@@ -27,9 +28,9 @@ class Solution {
2728
if(diff_pos.empty())
2829
return true;
2930
// only one pair of diff positions, check if swapping makes them equal
30-
if(diff_pos.size() == 2)
31+
if(diff_pos.size() == 2)
3132
swap(s1[diff_pos[0]], s1[diff_pos[1]]);
32-
33+
3334
return s1 == s2;
3435
}
35-
};
36+
};

0 commit comments

Comments
 (0)