Given two strings s
and t
, return true
if t
is an anagram of s
, and false
otherwise.
Example 1:
Input: s = "anagram", t = "nagaram" Output: true
Example 2:
Input: s = "rat", t = "car" Output: false
Constraints:
1 <= s.length, t.length <= 5 * 104
s
andt
consist of lowercase English letters.
My Code:
class Solution {
public boolean isAnagram(String s, String t) {
char c1[] = s.toCharArray();
char c2[] = t.toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
if(Arrays.equals(c1, c2)){
return true;
}
else{
return false;
}
}
}
No comments:
Post a Comment