005推断两个字符串是否是变位词 (keep it up)
写一个函数推断两个字符串是否是变位词。
变位词(anagrams)指的是组成两个单词的字符同样,但位置不同的单词。比方说,
abbcd和abcdb就是一对变位词
这也是简单的题。 我们能够排序然后对照, 也能够直接统计字符出现的个数来推断。这里给出统计字符来推断的代码:
bool isAnagram1(const string& vLeft, const string& vRight)
{
if (vLeft.size() != vRight.size()) return false;
int Count[256];
memset(Count, 0, sizeof(Count)); for (unsigned int i=0; i<vLeft.size(); ++i)
{
++Count[vLeft[i]];
--Count[vRight[i]];
} for (unsigned int i=0; i<vLeft.size(); ++i)
{
if (Count[vLeft[i]] !=0) return false;
} return true;
}
005推断两个字符串是否是变位词 (keep it up)的更多相关文章
- str_2.判断两个字符串是否互为旋转词
1. 字符串str的前面任意部分挪到后面形成的字符串叫做字符串str的旋转词 $str1 = "2ab1"; $str2 = "ab12"; $ret = is ...
- 剑指Offer:互为变位词
// 判断两个单词是否互为变位词: 如果两个单词中的字母相同,并且每个字母出现的次数也相同, 那么这两个单词互为变位词 #include <stdio.h> #include <st ...
- [Swust 549]--变位词(vector水过)
Time limit(ms): 1000 Memory limit(kb): 65535 Description 输入N和一个要查找的字符串,以下有N个字符串,我们需要找出其中的所有待查找字符串的 ...
- Lintcode--002(两个字符串是变位词)
写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 您在真实的面试中是否遇到过这个题? 样例 给出 s = "abcd", ...
- [LeetCode] Find All Anagrams in a String 找出字符串中所有的变位词
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
- java实现字符串匹配问题之求两个字符串的最大公共子串
转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/38924981 近期在项目工作中有一个关于文本对照的需求,经过这段时间的学习,总结 ...
- 【easy】438.Find All Anagrams in a String 找出字符串中所有的变位词
Input: s: "abab" p: "ab" Output: [0, 1, 2] Explanation: The substring with start ...
- lintcode-158-两个字符串是变位词
158-两个字符串是变位词 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 说明 What is Anagram? Two strings are ...
- [LeetCode] 438. Find All Anagrams in a String 找出字符串中所有的变位词
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
随机推荐
- Apache Kylin高级部分之使用Hive视图
本章节我们将介绍为什么须要在Kylin创建Cube过程中使用Hive视图.而假设使用Hive视图.能够带来什么优点.解决什么样的问题.以及须要学会怎样使用视图.使用视图有什么限制等等. 1. ...
- 自己动手写CPU之第七阶段(6)——乘累加指令实现思路
将陆续上传本人写的新书<自己动手写CPU>.今天是第29篇.我尽量每周四篇 亚马逊的销售地址例如以下,欢迎大家围观呵! http://www.amazon.cn/dp/b00mqkrlg8 ...
- 解决ORA-02395:超出I/O使用的调用限制问题
ORACLE的PROFILE文件是限制数据库用户使用的资源的一种手段.如:控制session或sql能使用的CPU.控制用户的password管理策略等. 数据库创建后,系统则存在名为DEFAULT的 ...
- sklearn中的数据预处理----good!! 标准化 归一化 在何时使用
RESCALING attribute data to values to scale the range in [0, 1] or [−1, 1] is useful for the optimiz ...
- zzulioj--1858--单词翻转(模拟)
1858: 单词翻转 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 88 Solved: 35 SubmitStatusWeb Board Desc ...
- BZOJ 2819 DFS序+线段树
非递归的DFS写炸了- 交了一个递归版的 过了---.. //By SiriusRen #include <cstdio> #include <cstring> #includ ...
- Spark RDD概念学习系列之如何创建Pair RDD
不多说,直接上干货! 创建Pair RDD Python语言 pairs = lines.map(lambda x: (x.split(], x)) scala语言 val pairs = line ...
- How to include custom library into maven local repository?--转
原文地址:https://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/ There ...
- Asp.net mvc中使用配置Unity
第一步:添加unity.mvc 第二步:在添加之后会在app_start中生成UnityConfig.cs,UnityMvcActivator.cs 第三步:使用 第四步:效果展示
- WINDOWS系统注册表(读、写)
读取注册表 写入注册表