leetcode-Valid Anagram
来源:互联网 发布:红外光谱分析软件 编辑:程序博客网 时间:2024/06/08 15:58
Difficulty: Easy
Given two strings s and t, write a function to determine ift is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
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; }};
0 0
- Leetcode #242 Valid Anagram
- leetcode-242-Valid Anagram
- Leetcode: Valid Anagram
- 【leetCode】Valid Anagram
- [leetcode] 242.Valid Anagram
- leetcode 242: Valid Anagram
- 【leetcode】Valid Anagram
- [leetcode] Valid Anagram
- LeetCode Valid Anagram
- 【LeetCode】242 Valid Anagram
- [LeetCode] Valid Anagram
- leetcode: Valid Anagram
- leetCode(53):Valid Anagram
- leetcode Valid Anagram 异位体
- [leetcode 242]Valid Anagram
- leetcode Valid Anagram
- leetCode #242 Valid Anagram
- LeetCode题解:Valid Anagram
- JavaScript ☞ JavaScript对象
- org.hibernate.TransactionException: commit failed
- Maximum subarray -- 最大子数组问题(C++)
- NOIP 考前注意
- 对底层软硬件的一些胡思乱想
- leetcode-Valid Anagram
- Android USB转串口编程
- java serialization/deserialization (序列化对象自描述)
- javaEE和javaSE的区别和联系
- K-均值算法
- HDU 2072 单词数【STL】
- Caused by: org.hibernate.TransactionException: unable to commit against JDBC connection
- 多线程下载断点下载
- JPA中L2 cache和query cache初探