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.
publicstaticintmakeAnagram(Stringa,Stringb){// Write your code here// simply adding and deleting might delete duplicate values from our second word int[]alphabet=newint[26];//count up for characters in our first wordfor(inti=0;i<a.length();i++){intindex=Math.abs(a.charAt(i)-'a');alphabet[index]++;}//the subtract for charcters in our second word, duplicate characters will show as negative numbersfor(intj=0;j<b.length();j++){intindexB=Math.abs(b.charAt(j)-'a');alphabet[indexB]--;}intdifferences=0;//ignore the sign of the integer to get a countfor(intcount:alphabet){differences+=Math.abs(count);}returndifferences;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
Java with comments