leetcode 有效的字母异位词

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;
    }
}
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页