Leetcode / 242. Valid Anagram
Pick a programming language:
Here is the source code for the solution to this problem.
class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) {
return false;
}
int[] counts = new int[26];
for (int i = 0; i < s.length(); i++) {
counts[s.charAt(i) - 'a']++;
counts[t.charAt(i) - 'a']--;
}
for (int i = 0; i < counts.length; i++) {
if (counts[i] != 0) {
return false;
}
}
return true;
}
}
Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: