Valid Anagram

来源:互联网 发布:斯托克顿生涯数据 编辑:程序博客网 时间:2024/05/23 11:56
Given two strings s and t, write a function to determine if t is an anagram of s.

For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.

Note:

You may assume the string contains only lowercase alphabets.

class Solution {public:    bool isAnagram(string s, string t)    {        int ht1[256] = {0};        for(int i = 0; i < s.size(); ++i)        {            ht1[s[i]]++;        }            int ht2[256] = {0};        for(int i = 0; i < t.size(); ++i)        {            ht2[t[i]]++;        }        for(int i = 0; i < 256; ++i)        {            if(ht1[i] != ht2[i])            {                return false;            }        }        return true;    }};


0 0
原创粉丝点击