LeetCode() Valid Anagram 有问题!!!
为什么第一个通过,第二个不行呢?
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 有问题!!!的更多相关文章
- [LeetCode] Valid Anagram 验证变位词
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...
- 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 ...
- LeetCode——Valid Anagram
Description: Given two strings s and t, write a function to determine if t is an anagram of s. For e ...
- LeetCode Valid Anagram (简单题)
题意: 给出两个字符串s和t,判断串t是否为s打乱后的串. 思路: 如果返回的是true,则两个串的长度必定相等,所有字符出现的次数一样.那么可以统计26个字母的次数来解决,复杂度O(n).也可以排序 ...
- leetcode面试准备:Valid Anagram
leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: 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: ...
随机推荐
- powershell加win的dns服务器,解决网站负载均衡问题
用我发明的powershell填坑法,加windows的dns服务器.从调整dns服务器解析ip时间段的角度,解决网站负载均衡问题. ------------------------win2012r2 ...
- 在VS中使用类模板出现出现LNK2019: 无法解析的外部符号错误。
在VS中使用类模板出现出现LNK2019: 无法解析的外部符号错误,应在一个.h文件中完成方法的声明与实现,不要将实现放在cpp文件里,VS貌似不支持类模板分离
- HTTPS Everywhere – 保障隐私和信息安全的利器
HTTPS Everywhere 是一款 Chrome 扩展程序,对于支持 HTTPS 的网站默认打开 HTTPS 加密传输来保障信息安全(HTTPS 介绍). HTTPS Everywhere 受到 ...
- C# Inject
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Di ...
- php中常用的运算符
运算符 运算符是告诉PHP做相关运算的标识符号. PHP运算符一般分为算术运算符.赋值运算符.比较运算符.三元运算符.逻辑运算符.字符串连接运算符.错误控制运算符. 1.变量名记得加“$” 符: 2. ...
- poj2891 拓展欧几里得
//Accepted 164 KB 16 ms //拓展欧几里得 //m=a1*x+b1 --(1) //m=a2*(-y)+b2 --(2) //->a1*x+a2*y=b2-b1 //由欧几 ...
- tableviewcell的取消选中,高亮
1.取消多余cell的分割线 UIView *view = [UIView new]; view.backgroundColor = [UIColor clearColor]; [tableView ...
- C/C++ memmove 和 memcpy
这两个函数用于拷贝字符串或者一段连续的内存,函数原型: void * memcpy ( void * destination, const void * source, size_t num ); v ...
- python global vs nonlocal (2)
上一篇中简述了这两个关键字的基本用法: global用于在局部作用于修改或重定义全局变量 nonlocal用于在内部作用域修改或重定义外部变量(全局变量除外) 这只是很浅的理解方式 注意python的 ...
- phpstom 实用laravel 需要附加的 命令
首先利用composer 下载相关的插件 在根目录执行此代码 composer require barryvdh/laravel-ide-helper 再者在config/app.php 添加一条命令 ...