The original algorithm is described as follows:
Given, Strings s and t, write a function to determine if it is a anagram of S.
for example,
s = "Anagram", T = "Nagaram", return true.
s = "Rat", t = "Car", return false.
translation: Determine whether a given two string is the same string that is scrambled in the order
my Java implementation:
Import Java.util.HashMap;
public class Solution {public
Boolean Isanagram (string s, String t) {
if (s.length ()! = T.length ())
{return FA LSE;
}
char[] C1 = S.tochararray ();
char[] C2 = T.tochararray ();
hashmap<character,integer> map1 = new hashmap<character,integer> ();
hashmap<character,integer> map2 = new hashmap<character,integer> ();
for (int i=0;i < s.length (); i++) {
if (!map1.containskey (C1[i])) {
map1.put (c1[i], 1);
} else{
map1.put (C1[i], Map1.get (C1[i]) +1);
}
if (!map2.containskey (C2[i])) {
map2.put (c2[i], 1);
} else{
map2.put (C2[i], Map2.get (C2[i]) +1);
}
}
if (Map1.entryset (). Containsall (Map2.entryset ()) && Map2.entryset (). Containsall (Map1.entryset ())) {
return true;
}
return false;
}
}