You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
414 B
24 lines
414 B
2 years ago
|
package class33;
|
||
|
|
||
|
public class Problem_0242_ValidAnagram {
|
||
|
|
||
|
public static boolean isAnagram(String s, String t) {
|
||
|
if (s.length() != t.length()) {
|
||
|
return false;
|
||
|
}
|
||
|
char[] str1 = s.toCharArray();
|
||
|
char[] str2 = t.toCharArray();
|
||
|
int[] count = new int[256];
|
||
|
for (char cha : str1) {
|
||
|
count[cha]++;
|
||
|
}
|
||
|
for (char cha : str2) {
|
||
|
if (--count[cha] < 0) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
}
|