Valid Anagram
class Solution {
public:
bool isAnagram(string s, string t) {
if(t=="") return s=="";
map<char,int> m_s;
map<char,int> m_t;
int i=;
while(i<t.length()){
if(m_t.find(t[i]) != m_t.end()) m_t[t[i]]++;
else m_t.insert(pair<char,int>(t[i],));
i++;
}
i=;
while(i<s.length()){
if(m_s.find(s[i]) != m_s.end()) m_s[s[i]]++;
else m_s.insert(pair<char,int>(s[i],));
i++;
}
map<char,int >::iterator it;
for(it=m_s.begin();it!=m_s.end();it++){ //s belong t
if(m_t[it->first] != it->second)
{return false;}
}
for(it=m_t.begin();it!=m_t.end();it++){ //t belong s
if(m_s[it->first] != it->second)
{return false;}
}
return true;
}
};
Valid Anagram的更多相关文章
- 【09_242】Valid Anagram
Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...
- leetcode面试准备:Valid Anagram
leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...
- 242. Valid Anagram(C++)
242. Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 【LeetCode】242. Valid Anagram (2 solutions)
Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For ...
- [leetcode]242. Valid Anagram验证变位词
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...
- leetcdoe Valid Anagram
题目连接 https://leetcode.com/problems/valid-anagram/ Valid Anagram Description Given two strings s and ...
- LN : leetcode 242 Valid Anagram
lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...
- LeetCode_242. Valid Anagram
242. Valid Anagram Easy Given two strings s and t , write a function to determine if t is an anagram ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
随机推荐
- 深入SQL截取字符串(substring与patindex)的详解
首先学习两个函数1.substring 返回字符.binary.text 或 image 表达式的一部分.基本语法:SUBSTRING ( expression , start , length ) ...
- LIB和DLL的区别与使用
转这篇文章是因为以前有个误区,以为lib为静态库,dll为动态库,这理解并不错,但不全面.lib分两种的:(1) lib包含所有内容的静态库,应用程序用它即可,这是我理解的一种(2) lib只包含头部 ...
- [BS-23] AFN网络请求上拉/下拉刷新的细节问题总结
上拉/下拉刷新的细节问题总结 1.如果导航栏有透明色,则也需要设置header自动改变透明度 self.tableView.mj_header.automaticallyChangeAlpha = Y ...
- Java 多线程Future和FutureTask
Future表示一个任务的周期,并提供了相应的方法来判断是否已经完成或者取消,以及获取任务的结果和取消任务. Future接口源码: public interface Future<V> ...
- category应用(计算nssting的数量)
// // main.m // 03-分类应用 // // Created by apple on 14-3-18. // Copyright (c) 2014年 apple. All rig ...
- AngularJS form表单验证(非常全面)
构建一个ng表单 novalidate=”novalidate” 2.form中不能有action属性.提交交由ng-submit处理 3.每个input一定要有ng-model,最好有一个name方 ...
- ios app下载跳到itunes
<body class="box"> <div class="text"> <a href="https://itune ...
- WAL
WAL record format typedef struct XLogRecord{pg_crc32 xl_crc; /* CRC for this record */XLogRe ...
- 【Origin】 破阵子-未可留 征人调
几朝岁月,悠悠,容颜改,两鬓衰,可恨荣光不留! 一生事,忧心畔,可怜惶惶,不拿年岁当缠头: 只把扑朔往往,人生几回首: 等闲识得料峭处,一腔泪流: 曾记否,三十功名尘与土,不可解忧愁: 青春换得明日花 ...
- 解决HierarchyViewer不能连接真机的问题
今天想通过HierarchyViewer分析一下Android应用的布局,但是发现无法连接上真机,错误如下: 1 2 3 4 5 [hierarchyviewer]Unable to get ...