为什么第一个通过,第二个不行呢?

class Solution {
public:
bool isAnagram(string s, string t) {
if(s.size() != t.size())
return false;
vector<int> coll(26,0);
for(long i=0;i<s.size();i++)
{
coll[s[i]-'a']++;
}
for(long i=0;i<s.size();i++)
{
if(coll[t[i]-'a'] == 0)
return false;
else
coll[t[i]-'a']--;
}
for(auto i:coll)
{
if(i != 0)
return false;
}
return true;
}
};

  

class Solution {
public:
bool isAnagram(string s, string t) {
if(s.size() != t.size())
return false;
vector<long> coll(26,0);
for(long i=0;i<s.size();i++)
{
coll[s[i]-'a']++;
}
for(long i=0;i<s.size();i++)
{
if(coll[t[i]-'a'] == 0)
return false;
coll[t[i]-'a']--;
}
for(int i=0;i<s.size();i++)
if(coll[i] != 0)
return false;
return true;
}
};

  

LeetCode() Valid Anagram 有问题!!!的更多相关文章

  1. [LeetCode] Valid Anagram 验证变位词

    Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...

  2. Leetcode Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  3. LeetCode——Valid Anagram

    Description: Given two strings s and t, write a function to determine if t is an anagram of s. For e ...

  4. LeetCode Valid Anagram (简单题)

    题意: 给出两个字符串s和t,判断串t是否为s打乱后的串. 思路: 如果返回的是true,则两个串的长度必定相等,所有字符出现的次数一样.那么可以统计26个字母的次数来解决,复杂度O(n).也可以排序 ...

  5. leetcode面试准备:Valid Anagram

    leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...

  6. LeetCode 242. 有效的字母异位词(Valid Anagram)

    242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...

  7. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  8. 【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 ...

  9. [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: ...

随机推荐

  1. Problem C HDU 5224

    Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows t ...

  2. selectNodes

    解析beans.xml的时候有时候找不到节点,把其他多余的删除之后就好了,不知道为什么.

  3. dotTracePerormance 工具

    今天凌晨 阿根廷对瑞士比赛已经过去,比分是1:0  阿根廷获胜:虽说我是伪球迷,但是也挺希望梅西进入决赛.昨晚也压了下90分之内  0:0  ,结果胜出:另一场压的是美国对比利时,也是压平,就这样二串 ...

  4. HDU 3829 - Cat VS Dog (二分图最大独立集)

    题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...

  5. 【转】FFMPEG 库移植到 VC 需要的步骤

    原文:http://blog.csdn.net/leixiaohua1020/article/details/12747899 在VC下使用FFMPEG编译好的库,不仅仅是把.h,.lib,.dll拷 ...

  6. spring六种种依赖注入方式

    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...

  7. Note_Master-Detail Application(iOS template)_07_ YJYDetailViewController.m

    //  YJYDetailViewController.m #import "YJYDetailViewController.h" @interfaceYJYDetailViewC ...

  8. Java三大主流开源工作流引擎技术分析

    首先,这个评论是我从网上,书中,搜索和整理出来的,也许有技术点上的错误点,也许理解没那么深入.但是我是秉着学习的态度加以评论,学习,希望对大家有用,进入正题! 三大主流工作流引擎:Shark,oswo ...

  9. 修改主机名Ubuntu

    主机名存放在/etc/hostname 修改保存即可

  10. linux命令:cp

    1.命令介绍: cp用来复制文件或目录,全称是copy 2.命令格式: cp [选项] [-T] 源 目的 或cp [选项] 源 目录 或cp [选项] -t 目录 源 3.命令参数: -a, --a ...