Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cad05da

Browse files
authored
Create Check Whether Two Strings are Almost Equivalent.java
1 parent 134f714 commit cad05da

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public boolean checkAlmostEquivalent(String word1, String word2) {
3+
int[] counter = new int[26];
4+
for (int i = 0; i < word1.length(); i++) {
5+
counter[word1.charAt(i) - 'a']++;
6+
counter[word2.charAt(i) - 'a']--;
7+
}
8+
return IntStream.range(0, 26).allMatch(idx -> Math.abs(counter[idx]) <= 3);
9+
}
10+
}

0 commit comments

Comments
 (0)