您好,登錄后才能下訂單哦!
242. Valid Anagram
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.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
class Solution { public: bool isAnagram(string s, string t) { if(s.size() != t.size()) { return false; } else { int sBit[26] = {0};//記錄每個字母出現的次數 int tBit[26] = {0}; const char * sp = s.c_str(); const char * tp = t.c_str(); for(int i = 0; i < s.size() ; i++) { sBit[*(sp+i) - 'a']++; tBit[*(tp+i) - 'a']++; } for(int j = 0; j < 26;j++) { if(sBit[j] != tBit[j]) { return false; } } return true; } } };
2016-08-05 13:52:07
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。