Check Whether Two Strings are Almost Equivalent LeetCode solution in Java
1class Solution {2public boolean checkAlmostEquivalent(String word1, String word2) {3Map<Character, Integer> map = new HashMap();4for (int i = 0; i < word1.length(); i++) {5map.put(word1.charAt(i), map.getOrDefault(word1.charAt(i), 0) + 1);6map.put(word2.charAt(i), map.getOrDefault(word2.charAt(i), 0) - 1);7}8for (int i : map.values()) { // get value set9if (i > 3 || i < -3) {10return false;11}12}13return true;14}15}