设为首页 加入收藏

TOP

LeetCode242――Valid Anagram
2015-11-21 00:56:19 来源: 作者: 【 】 浏览:1
Tags:LeetCode242 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.

实现:
class Solution {
public:
bool isAnagram(string s, string t) {
if (s.size() != t.size()) return false;
int bit[26] = {0}, len = s.length();

for(int i=0; i bit[s[i]-'a']++;

for(int i=0; i if(--bit[t[i]-'a'] < 0)
return false;
return true;
}
};

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdoj 最简单的计算机 下一篇UVA 11235 Frequent values (RMQ)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: