leetcode 242. Valid Anagram
来源:互联网 发布:instasize 相机软件 编辑:程序博客网 时间:2024/06/03 08:53
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?
class Solution {public: bool isAnagram(string s, string t) { //way-1 /* sort(s.begin(), s.end()); sort(t.begin(), t.end()); return s == t; */ //way-2 if(s.size() != t.size()) return false; map<char,int> mm; for(int i = 0; i < s.size(); i++) mm[s[i]]++; for(int i = 0; i < t.size(); i++) { auto it = mm.find(t[i]); if(it == mm.end()) return false; mm[t[i]]--; if (mm[t[i]] == 0) mm.erase(it); } return mm.size() == 0; }};
阅读全文
0 0
- [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
- SSH项目访问action报错
- 使用map迭代器中遇到的问题——非const转成const类型造成的编译错误
- EMI
- CAB6伺服穿气袋位置更改问题
- DSS 代码分析【Reliable UDP之数据重传】
- leetcode 242. Valid Anagram
- 如何处理前任留下的代码
- 接口调试插件RESTED使用post的方法
- 数据结构与算法分析(Java语言描述)(32)—— 使用 Kruskal 算法求有权图的最小生成树
- 混合游戏环境:让人类一直身处在物联网中(作业 全靠google)
- pg数据库查询重复数据并可识别空数据列重复
- 树莓派 linux下modbus总结(TCP-modbus,RS232-modbus)
- cookie和session的区别
- 虚函数导引学习一