You are viewing a single comment's thread. Return to all comments →
static boolean isAnagram(String a, String b) { // Complete the function java.util.Map<Character, Integer> stringAMap = new java.util.HashMap<>(); java.util.Map<Character, Integer> stringBMap = new java.util.HashMap<>(); if(a.length() == b.length()) { for(int i = 0; i < a.length(); i++){ stringAMap.compute(a.toLowerCase().charAt(i), (key, value) -> value == null ? 1 : value + 1); stringBMap.compute(b.toLowerCase().charAt(i), (key, value) -> value == null ? 1 : value + 1); } if(stringAMap.equals(stringBMap)){ return true; } return false; } return false; }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Anagrams
You are viewing a single comment's thread. Return to all comments →