We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscan=newScanner(System.in);Stringx=scan.nextLine();Stringy=scan.nextLine();if(x.length()!=y.length()){System.out.println("Not Anagrams");}else{HashMapletters_x=countLetters(x.toLowerCase());HashMapletters_y=countLetters(y.toLowerCase());if(letters_x.equals(letters_y)){System.out.println("Anagrams");}else{System.out.println("Not Anagrams");}}}publicstaticHashMapcountLetters(Stringstr){HashMap<Character,Integer>letters=newHashMap<>();for(inti=0;i<str.length();i++){intcontador=0;letters.put(str.charAt(i),contador);for(intj=0;j<str.length();j++){if(str.charAt(i)==str.charAt(j)){contador++;letters.put(str.charAt(i),contador);}}}returnletters;}}
Cookie support is required to access HackerRank
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 →