Skip to content

Commit

Permalink
Q1790 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Mar 10, 2023
1 parent 8ed743b commit 0649fd7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions E_1790_CheckifOneStringSwapCanMakeStringsEqual.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public boolean areAlmostEqual(String s1, String s2) {
if(s1.length()!=s2.length())
return false;
int mis=0;
int[] chars1 = new int[26];
int[] chars2 = new int[26];

for(int i=0; i<s1.length(); i++){
if(s1.charAt(i)!=s2.charAt(i))
mis++;
chars1[s1.charAt(i)-'a']++;
chars2[s2.charAt(i)-'a']++;
}
for(int i=0; i<26; i++){
if(chars1[i]!=chars2[i])
return false;
}
return mis > 2? false : true;
}
}

0 comments on commit 0649fd7

Please sign in to comment.