File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
public boolean isAnagram (String s , String t ) {
3
-
4
3
if (s .length () != t .length ()) return false ;
5
- if (s .equals (t )) return true ;
6
-
7
- Map <Character , Integer > sMap = new HashMap <>();
8
- Map <Character , Integer > tMap = new HashMap <>();
9
-
10
- for (int i = 0 ; i < s .length (); i ++) {
11
- sMap .merge (s .charAt (i ), 1 , Integer ::sum );
12
- tMap .merge (t .charAt (i ), 1 , Integer ::sum );
13
- }
14
-
15
- for (Character c : sMap .keySet ()) {
16
- if (!sMap .get (c ).equals (tMap .get (c ))) return false ;
4
+
5
+ int [] store = new int [26 ];
6
+
7
+ for (int i =0 ; i <s .length (); i ++){
8
+ store [s .charAt (i ) - 'a' ]++;
9
+ store [t .charAt (i ) - 'a' ]--;
17
10
}
11
+
12
+ for (int n :store )
13
+ if (n != 0 )
14
+ return false ;
15
+
18
16
return true ;
19
17
}
20
- }
18
+ }
You can’t perform that action at this time.
0 commit comments