34 / 34 个通过测试用例
状态:通过
执行用时:4 ms
内存消耗:37.3 MB
class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length())return false;
int countS = 0;
int countT = 0;
int indexS = 0;
int indexT = 0;
for (char le = 'a'; le < 'z'; le++) {
while ((indexS = s.indexOf(le,indexS)) != -1){
countS++;
indexS+=1;
}
while ((indexT = t.indexOf(le,indexT)) != -1){
countT++;
indexT+=1;
}
if (countS != countT) return false;
}
return true;
}
}