LeetCode 242 有效的字母异位词

class Solution {
public:
    bool isAnagram(string s, string t) {
        if (s.size() != t.size()) return false;

        sort(s.begin(), s.end());
        sort(t.begin(), t.end());

        for (int i = 0; i < s.size(); i ++) {
            if (s[i] != t[i]) return false;
        }

        return true;
    }
};
posted @ 2022-09-05 15:47  hjy94wo  阅读(9)  评论(0)    收藏  举报