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 ...
随机推荐
- hdu 4717 The Moving Points(三分)
http://acm.hdu.edu.cn/showproblem.php?pid=4717 大致题意:给出每一个点的坐标以及每一个点移动的速度和方向. 问在那一时刻点集中最远的距离在全部时刻的最远距 ...
- 4种方法让SpringMVC接收多个对象
问题背景: 我要在一个表单里同一时候一次性提交多名乘客的个人信息到SpringMVC,前端HTML和SpringMVC Controller里该怎样处理? 第1种方法:表单提交,以字段数组接收: 第2 ...
- Spring使用HibernateDaoSupport操作数据
spring提供了一个数据訪问层的类:org.springframework.orm.hibernate3.support.HibernateDaoSupport.一般是让 dao继承该类,然后在da ...
- iOS-获取Model(设备型号)、Version(设备版本)、app(程序版本)等
IOS-获取Model(设备型号).Version(设备版本).app(程序版本)等 NSLog(@"uniqueIdentifier: %@", [[UIDevice curre ...
- Spring Data MongoDB 五:进阶文档查询(分页、Morphia)(二)
Spring Data MongoDB 三:基本文档查询(Query.BasicQuery)(一) 学习MongoDB 六: MongoDB查询(游标操作.游标信息)(三) 一.简单介绍 Spring ...
- 指针,c语言的灵魂
指针是一个值为内存地址的变量. 变量是一块内存空间,指针是变量,是用来存储内存地址的变量. #include <stdio.h> #include <stdlib.h> int ...
- UESTC--1265--宝贵资源(简单数学)
宝贵资源 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu Submit Status Des ...
- weblogic状态监控脚本
echo "======================================welcome============================================ ...
- javascript前端如何使用google-protobuf
1.首先下载google的protobuf的compiler,通过编译器可以将.proto文件转换为想要的语言文件. 下载地址:https://repo1.maven.org/maven2/com/g ...
- IBM 总架构师:话说程序员的职业生涯
作者:IBM 软件集团大中华区总架构师 寇卫东 有一些年轻的程序员向我咨询,将来的路应该怎么走?俗话说,条条大路通罗马.不同的路都能走向成功.到底选哪条路,取决于自己的兴趣.可能有程序员会问:如果还没 ...