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.
publicstaticintanagram(Strings){if(s.length()%2!=0)return-1;intsize=s.length()/2;int[]s1=newint[26];intbase='a';intchanges=0;//build first halffor(inti=0;i<size;i++){s1[s.charAt(i)-base]++;}//check second halffor(inti=size;i<size*2;i++){if(s1[s.charAt(i)-base]>0)s1[s.charAt(i)-base]--;elsechanges++;}returnchanges;}
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 →
Minimalist O(n) solution: