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 ...
随机推荐
- 洛谷 U5737 纸条
U5737 纸条 题目背景 明明和牛牛是一对要好的朋友,他们经常上课也想讲话,但是他们的班级是全校纪律最好的班级,所以他们只能通过传纸条的方法来沟通.但是他们并不能保证每次传纸条老师都无法看见,所以他 ...
- 页面安装Jre
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height ...
- PowerDesigner16 破解
近期开发项目,涉及到实体设计这块的时候,用的是PowerDesigner16,使用是挺方便的,可是存在一个问题.那就是PowerDesigner16存在一个试用期的问题,过期就打不开了. 之前好多同学 ...
- java中继承关系学习小结
继承:把多个类中同样的内容提取出来.定义到一个类中,其它类仅仅须要继承该类.就能够使用该类公开的属性和公开的方法. 继承的优点:提高代码的复用性.提高代码的可维护性.让类与类之间产生关系,是多态存 ...
- hdu1181(变形课)
点击打开链接 Problem Description 呃......变形课上Harry碰到了一点小麻烦,由于他并不像Hermione那样可以记住全部的咒语而任意的将一个棒球变成刺猬什么的,可是他发现了 ...
- Toast分析——实现自己的Toast
android 4.0以后,新增了一个功能:关闭某个应用发出的通知.Toast等.详细操作为:打开应用安装列表.找到要屏蔽的应用(长按通知,点击弹出的"应用信息",就可以跳到应用信 ...
- C# DispatcherTimer Start之后立即执行
如果DispatherTimer 的Interval 不是在实例化时赋值,那么Start之后,Tick方法会立即执行一次. DispatcherTimer timer = new Dispatcher ...
- UVA 1515 Pool construction 最大流跑最小割
Pool construction You are working for the International Company for Pool Construction, a constructio ...
- pcap文件生成metadata——使用tshark解析tcpdump的pcap包
pcap文件生成metadata #!/usr/bin/env python # -*- coding: utf-8 -*- import os import time, datetime impor ...
- 个人作业—Alpha项目测试
这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 这个作业要求在哪里 https://edu.cnblo ...