leetcode-Valid Anagram
2015-11-05 23:24
344 查看
Difficulty:
Easy
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
Easy
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
class Solution { public: bool isAnagram(string s, string t) { map<char,int> check; int nonZero=0; for(auto &e:s) if(++check[e]==1) ++nonZero; for(auto &e:t){ if(--check[e]==0) --nonZero; else if(check[e]==-1) ++nonZero; } return nonZero==0; } };
相关文章推荐
- NOIP 考前注意
- org.hibernate.TransactionException: commit failed
- solr配置文件solrconfig.xml解析
- 对底层软硬件的一些胡思乱想
- SVM入门(九)松弛变量(续)
- jquery 图片比例不变,全屏居中
- Maximum subarray -- 最大子数组问题(C++)
- JavaScript ☞ JavaScript对象
- python学习笔记-Web环境搭建
- Using Redis to store php session
- [LeetCode]Merge Two Sorted Lists
- python线程详解
- CSS3实现Bootstrap的tooltip动画提示效果
- java设计模式--原型模式(Prototype)
- python中对list去重的多种方法
- EasyMock使用方法和原理详解
- startService和bindService混合使用分析
- json学习笔记_01_json语法基本格式并s会用java读取json
- i2c--2.6.34文档:如何枚举产生i2c_client
- j2ee web.xml 中url-pattern匹配