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 ...
随机推荐
- 微信域名weixin.com天价成交!是腾讯吗?
据业内人士爆料,“微信”双拼域名weixin.com已于今天交易了,成交价格8位数.如此大手笔,神秘买家会是腾讯吗? 通过查询该域名的whois信息,最近一次的更新时间显示为今年4月13日,注册邮箱信 ...
- 细聊分布式ID生成方法
细聊分布式ID生成方法 https://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=403837240&idx=1&sn=ae9 ...
- 集群中用Memcached来实现session共享
这几天在实现nginx集群的过程中,发现session使用存在问题,登录页面后有时候需要重复登录,和开发部沟通后,决定采用memcached来实现session的共享,这也是各大型网站推荐的方式.开发 ...
- Http 四种请求访问代码 HttpGet HttpPost HttpPut HttpDelete .
String url = "http://www.baidu.com"; //将要访问的url字符串放入HttpPost中 HttpPost httpPost= new HttpP ...
- [ROS] slam_gmapping
slam_gmapping节点 1)slam_gmapping 节点在sensor_msgs/LaserScan消息内获取数据并建立地图 map(nav_msgs/OccupancyGrid).该地图 ...
- PostgreSQL 对字段大小写敏感
缘起 iso=> \d+ test; Table "public.test" Column | Type | Modifiers | Storage | Descriptio ...
- HBase shell
进入命令行 ./hbase shell 查看HBase shell帮助 help 查看命令帮助 直接输入命令回撤 创建命名空间 create_namespace 'ns1' 查看命名空间 list_n ...
- [chrome插件] 利滚利计算器 银行存款 基金理财 余额宝收益计算
利滚利计算在数学上是否有一个简单的公式,我不知道,但作为程序员,这个算法实现起来就是小菜一碟.作为插件发布,是因为程序确实简单,也方便Chome浏览器使用者安装.如果你也想使用一下Chrome插件,参 ...
- iOS UITableView的分割线短15像素,移动到最左边的方法(iOS8)
有好几个朋友问我ios 分割线端了一些 如何解决,于是我就写一篇博客吧.为什么我说是少了15像素呢?首先我们拖拽一个默认的tableview 控件! 看下xcode5 面板的inspector(检查器 ...
- django上传下载大文件
上传 def upFile(file): upload_dir = '/tmp/upload/%s' % username if request.method == 'POST': upload_fi ...