【leetcode】242. Valid Anagram
problem
首先,要先弄清楚什么是anagram,anagram是指由颠倒字母顺序组成的单词。
解决方法一种是排序,一种是哈希表。
solution:
class Solution { public: bool isAnagram(string s, string t) { if(s.length()!=t.length()) return false; int counts[26] = {0};//err for(int i=0; i<s.length(); i++) { counts[s[i]-'a']++; counts[t[i]-'a']--; } for(int i : counts) { if(i!=0) return false; } return true; } };
参考
1. Leetcode_242_Valid Anagram;
完
各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/