ImportJava.util.*; Public classSame { Public BooleanChecksam (String Stringa, String stringb) {//Write code here int[] str1=New int[256]; int[] str2=New int[256]; if(Stringa.length ()! =stringb.length ()) { return false; } for(intI=0;i<stringa.length (); i++) {Str1[stringa.charat (i)]++; Str2[stringb.charat (i)]++; } for(intj=0;j<256;j++){ if(str1[j]!=Str2[j]) { return false; } } return true; }}
Note the points:
1. You can use ToCharArray () and Str.charat (i) two ways to get each bit of the string
The 2.char type can be automatically converted to the int type. Converts the char type to the ASCII code corresponding to the character
3.int[] str1=new int[256] global variable no initial value defaults to 0, if int[] str; The default value is null. Global variable integer default value is also 0; local variables are not initialized automatically
4. Drawer algorithm, n+1 a ball into n drawers inside, at least one drawer inside more than 1 balls. In the same way, all ASCII characters are 256 and stored in a hash table.
Java lookup string1 and string2 are not the same letter type and number (string1 is string2 re-composition)