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.
staticbooleanisCharConsidered(char[]chs,charch){for(inti=0;i<chs.length;i++){if(chs[i]==ch)returntrue;}returnfalse;}staticintgetCntOfChar(byte[]chs,charch){intres=0;for(inti=0;i<chs.length;i++){if(chs[i]==ch)res++;}returnres;}staticbooleanisAnagram(Stringa,Stringb){if(a.length()!=b.length())returnfalse;// Complete the functionbyte[]acs=a.toLowerCase().getBytes();byte[]bcs=b.toLowerCase().getBytes();intnextChar=0;char[]chars=newchar[a.length()];for(inti=0;i<a.length();i++){if(!isCharConsidered(chars,a.charAt(i))){chars[nextChar++]=a.charAt(i);if(getCntOfChar(acs,a.charAt(i))!=getCntOfChar(bcs,a.charAt(i)))returnfalse;}}returntrue;}
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 →
My solution :)