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.
static boolean isAnagram(String a, String b) {
// Complete the function
if (a.length()!=b.length()) return false;
a = a.toLowerCase();
b = b.toLowerCase();
int[] s = new int[200];
char[] a1 = a.toCharArray();
char[] b1 = b.toCharArray();
for (int i=0; i<a.length(); i++)
{
s[(int)a1[i]]++;
}
for (int i=0; i<b.length(); i++)
{
s[(int)b1[i]]--;
}
for (int num : s){
if (num!=0) return false;
}
return true;
}
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 →