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

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. Codeforce385C 树状数组+素因子分解

    题目大意: 给多个区间的询问,在询问区间内每一个出现的素数去计算所有数中有多少个数能被这个素数整除 然后将所有素数得到的对应值求和 这里因为初始给定的数不超过10000000,最多670000不到的素 ...

  2. 【转发】linux文件系统变为只读的修复

    详细解决方法:http://smartmontools.sourceforge.net/badblockhowto.html 相关问题,更换硬盘:http://blog.chinaunix.net/u ...

  3. xlistview的java(头)

    package com.bwie.xlistviews; import com.bwie.test.R; import android.content.Context;import android.u ...

  4. NABCD分析

    NABCD——今日事 N(Need):开创的成就系统可以在一定程度上督促用户坚持下来. A(Approach):做一个APP软件,是在android平台构建. B(Benefit):可以逐步改变用户的 ...

  5. HTML--7JavaScript的DOM操作

    1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方法: 属性(值或者子对象): op ...

  6. 主线程中一定不能放耗时操作,必须要开子线程,比如下载文件,不然会不让你拿到输入流--报错显示android.os.NetworkOnMainThreadException

    1.必须要开子线程来操作耗时操作,android.os.NetworkOnMainThreadException new Thread(new Runnable() { @Override publi ...

  7. Notification通知栏

    Notification通知栏 首先实现的功能就是通知栏显示Notification,Notification是显示在系统的通知栏上面的,所以Notification 是属于进程之前的通讯.进程之间的 ...

  8. 使用hadoop multipleOutputs对输出结果进行不一样的组织

    MapReduce job中,可以使用FileInputFormat和FileOutputFormat来对输入路径和输出路径来进行设置.在输出目录中,框架自己会自动对输出文件进行命名和组织,如:par ...

  9. 【LeetCode OJ】Word Ladder I

    Problem Link: http://oj.leetcode.com/problems/word-ladder/ Two typical techniques are inspected in t ...

  10. UI基础:UITableView的编辑和移动

    相对UITableViiew进行编辑,必须设置代理,让代理遵循UITableViewDataSource和UITableViewDelegate协议.因为需要代理实现协议中几个必须的方法. UITab ...