class Solution {
public boolean isAnagram ( String s, String t) {
int len = s. length ( ) ;
if ( len!= t. length ( ) ) {
return false ;
}
int [ ] count = new int [ 26 ] ;
for ( int i= 0 ; i< len; i++ ) {
count[ s. charAt ( i) - 'a' ] ++ ;
}
for ( int i= 0 ; i< len; i++ ) {
if ( -- count[ t. charAt ( i) - 'a' ] < 0 ) {
return false ;
}
}
return true ;
}
}
class Solution {
public boolean isAnagram ( String s, String t) {
if ( s. length ( ) != t. length ( ) ) {
return false ;
}
Map< Character, Integer> map = new HashMap < Character, Integer> ( ) ;
int len = s. length ( ) ;
for ( int i= 0 ; i< len; i++ ) {
Integer num = map. get ( s. charAt ( i) ) ;
if ( num== null) {
map. put ( s. charAt ( i) , 1 ) ;
} else {
map. put ( s. charAt ( i) , num+ 1 ) ;
}
}
for ( int i= 0 ; i< len; i++ ) {
Integer num = map. get ( t. charAt ( i) ) ;
if ( num== null) {
return false ;
} else {
if ( -- num< 0 ) {
return false ;
} else {
map. put ( t. charAt ( i) , num) ;
}
}
}
return true ;
}
}