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.
Java 8
This is one of the easiest way to solve this problem.
publicstaticintanagram(Strings){intn=s.length();if(n%2!=0){return-1;}//Split the main stringStringleft=s.substring(0,n/2);Stringright=s.substring(n/2,n);//Iterate the left string to verify if the letters are contained into the // right stringfor(inti=0;i<n/2;i++){if(right.contains(left.substring(i,i+1))){right=right.replaceFirst(left.substring(i,i+1),"");}}returnright.length();}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →
Java 8 This is one of the easiest way to solve this problem.