#Leetcode# 242. Valid Anagram

https://leetcode.com/problems/valid-anagram/

Given two strings s and , write a function to determine if t is an anagram of s.

Example 1:

Input: s = "anagram", t = "nagaram"
Output: true

Example 2:

Input: s = "rat", t = "car"
Output: false

代码:

class Solution {
public:
    bool isAnagram(string s, string t) {
        map<char, int> mp;
        int ls = s.length(), lt = t.length();
        if(ls != lt) return false;
        for(int i = 0; i < ls; i ++)
            mp[s[i]] ++;
        for(int i = 0; i < lt; i ++)
            mp[t[i]] --;
        
        for(int i = 0; i < ls; i ++) {
            if(mp[s[i]]) return false;
            else continue;
        }
        return true;
    }
};

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9963461.html