leetcode 242. Valid Anagram
2016-02-24 14:41
281 查看
传送门
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?
Subscribe to see which companies asked this question
Hide Tags
Hash Table Sort
Show Similar Problems
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?
Subscribe to see which companies asked this question
Hide Tags
Hash Table Sort
Show Similar Problems
class Solution { public: bool isAnagram(string s, string t) { int scount[100]; int tcount[100]; memset(scount,0,sizeof(scount)); memset(tcount,0,sizeof(tcount)); string::iterator it; for(it = s.begin();it != s.end();it++){ scount[ (*it) - 'a' ] ++; } for(it = t.begin();it != t.end();it++){ tcount[ (*it) - 'a' ] ++; } for(int i = 0; i < 26 ;i++){ if(scount[i] != tcount[i]){ return false; } } return true; } };
相关文章推荐
- s:set拼接字符串以及s标签中数组的用法
- zookeeper简单的集群配置!
- 今天心情很好
- iOS里加载https请求报错说服务器证书无效的解决办法
- 【xv6学习之lab3】User Environment
- 打开Android本地Api文档缓慢的问题
- eclipse如何提供自动提示
- 在Azure上的VM镜像库中找到想要的镜像
- 深入hibernate的三种状态
- LVS负载均衡之NAT配置
- 在线HTTP速度测试(响应时间测试)及浏览器兼容测试
- iOS-OC-UISearchBar取消搜索状态
- xcode7新建类别、扩展
- idea 快捷键
- css3常用动画+动画库
- paper 29 :CV会议+领先研究室+专家+代码网址
- 四 HBase 客户端设置缓存优化查询。
- Jsp开发整理
- 键盘的通知 文本框跟随键盘移动
- 用C语言举例讲解数据结构中的算法复杂度结与顺序表