LeetCode 242. Valid Anagram
来源:互联网 发布:java pop3 编辑:程序博客网 时间:2024/05/22 13:16
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?
UniCode Characters VS Ascii Characters.
A standard for representing characters as integers. Unlike ASCII, which uses 7 bits for each character, Unicode uses 16 bits, which means that it can represent more than 65,000 unique characters. This is a bit of overkill for English and Western-Europeanlanguages, but it is necessary for some other languages, such as Greek, Chinese and Japanese. Many analysts believe that as thesoftware industry becomes increasingly global, Unicode will eventually supplant ASCII as the standard character codingformat.
Method1:
bool isAnagram(string s, string t) { if(s.size() != t.size()) return false; // anagrams should have the same size. sort(s.begin(), s.end()); sort(t.begin(), t.end()); // anagrams after sorting should be the same. return s == t; }
Method2: HashMap.... unordered_map<int, int> CharactersToCount;
- [leetcode] 242.Valid Anagram
- leetcode 242. Valid Anagram
- [leetcode] 242. Valid Anagram
- leetCode 242. Valid Anagram
- Leetcode 242. Valid Anagram
- 242. Valid Anagram LeetCode
- LeetCode 242. Valid Anagram
- LeetCode 242. Valid Anagram
- [LeetCode]242. Valid Anagram
- 【LeetCode】242. Valid Anagram
- leetcode 242. Valid Anagram
- leetcode 242. Valid Anagram
- LeetCode--242. Valid Anagram
- LeetCode *** 242. Valid Anagram
- #leetcode#242. Valid Anagram
- leetcode 242. Valid Anagram
- LeetCode 242. Valid Anagram
- 242.[LeetCode]Valid Anagram
- Android获取NavigationView header中的控件
- 浅谈mysql数据库存储引擎的选择
- Android开发之裁切(拍照+相册)图像并设置头像小结
- LeetCode 35. Search Insert Position
- LeetCode 237. Delete Node in a Linked List
- LeetCode 242. Valid Anagram
- 常用排序和查询
- 动态规划 和 图遍历的结合应用
- POJ1860 Currency Exchange(最短路径)
- Linux命令详解(1) – ls
- Linux命令详解(2) – mv
- 进阶光照与材质之光照和反射模型
- iOS开发中的一些坑
- 快速完成代码插入神器Exynap