-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path242.java
More file actions
43 lines (42 loc) · 1.22 KB
/
242.java
File metadata and controls
43 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
__________________________________________________________________________________________________
sample 1 ms submission
class Solution {
public boolean isAnagram(String s, String t) {
int[] frequency = new int[256];
for(char c: s.toCharArray()){
frequency[c]++;
}
for(char c: t.toCharArray()){
frequency[c]--;
}
for(int i = 0; i < 256; i++){
if(frequency[i] != 0){
return false;
}
}
return true;
}
}
__________________________________________________________________________________________________
sample 34180 kb submission
class Solution {
public boolean isAnagram(String s, String t) {
if(s.length() != t.length()){
return false;
}
int[] alphas = new int[26];
for(int ch : s.toCharArray()){
alphas[ch - 'a']++;
}
for(int ch : t.toCharArray()){
alphas[ch - 'a']--;
}
for(int i : alphas){
if (i != 0){
return false;
}
}
return true;
}
}
__________________________________________________________________________________________________