LeetCode 242. Valid Anagram
2016-07-22 13:41
239 查看
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?
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) { int a[26] = {0}; if(s.length() != t.length()) return 0; for(int i = 0; i < s.length(); i++) { a[s[i] - 'a']++; } for(int i = 0; i < t.length(); i++) { a[t[i] -'a']--; } for(int i = 0; i < 26; i++) { if(a[i] != 0) { return 0; } } return 1; } };
相关文章推荐
- 老程序员十年生涯黯然总结
- BZOJ2342 Manacher + set
- 怎么更改win7登录界面 梦幻桌面动态效果电脑桌面快速分屏设置虚拟wifi热点方法_桌面图标弹出提示飞雪桌面日历自定义桌面
- 性能测试知多少---吞吐量
- 最快让你上手ReactiveCocoa之进阶篇
- vj P1547 逆转,然后再见(记忆化搜索)
- poj2823 单调队列以及双端队列(deque)
- Android Studio使用技巧之常用快捷键汇总
- Sublime Text编辑器的使用
- Linux下tomcat服务有关命令
- LeetCode 169. Majority Element
- Runtime.getRuntime().exec如何执行多行命令
- markdown 页面编辑器
- LibreOffice源码开发_重要数据结构
- 简单易行的用windows系统虚拟苹果mac操作系统 mac下android环境搭建笔记(android studio)
- LeetCode 206. Reverse Linked List
- LeetCode 217. Contains Duplicate
- Data Scraping Studio ™ - Web Scraping & Data Extraction Software
- 到底还是中国人,这官话都一套一套的
- Android使用UncaughtExceptionHandler捕获全局异常 android获取手机信息大全Java追加文件内容使用JavaMail发送邮件OkHttp获取系统时间