You are viewing a single comment's thread. Return to all comments →
You can just use one array here to store. Here is a better version of your code. I am halving your space requirement by 26 * 4 bytes.
int cArr[]=new int[26]; for(int i=0;i<s1.length();i++)cArr[s1.charAt(i)-97]++; for(int i=0;i<s2.length();i++)cArr[s2.charAt(i)-97]--; int count=0; for(int i=0;i<26;i++)count+=Math.abs(cArr[i]); System.out.println(count);
Cheers!
Seems like cookies are disabled on this browser, please enable them to open this website
Making Anagrams
You are viewing a single comment's thread. Return to all comments →
You can just use one array here to store. Here is a better version of your code. I am halving your space requirement by 26 * 4 bytes.
Cheers!