LintCode-两个字符串是变位词
题目描述:
写出一个函数 anagram(s, t)
去判断两个字符串是否是颠倒字母顺序构成的
给出 s="abcd"
,t="dcab"
,返回 true
- public class Solution {
- /**
- * @param s: The first string
- * @param b: The second string
- * @return true or false
- */
- public boolean anagram(String s, String t) {
- if(s.length() != t.length())
- return false;
- else{
- for(int i=0;i<t.length();i++){
- if(s.indexOf(t.charAt(i))!=-1){
- int j = s.indexOf(t.charAt(i));
- s = s.substring(0, j)+s.substring(j+1);
- }
- else{
- return false;
- }
- }
- return true;
- }
- }
- };
LintCode-两个字符串是变位词的更多相关文章
- Lintcode--002(两个字符串是变位词)
写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 您在真实的面试中是否遇到过这个题? 样例 给出 s = "abcd", ...
- lintcode-158-两个字符串是变位词
158-两个字符串是变位词 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 说明 What is Anagram? Two strings are ...
- 剑指Offer:互为变位词
// 判断两个单词是否互为变位词: 如果两个单词中的字母相同,并且每个字母出现的次数也相同, 那么这两个单词互为变位词 #include <stdio.h> #include <st ...
- [Swust 549]--变位词(vector水过)
Time limit(ms): 1000 Memory limit(kb): 65535 Description 输入N和一个要查找的字符串,以下有N个字符串,我们需要找出其中的所有待查找字符串的 ...
- [LeetCode] 49. Group Anagrams 分组变位词
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- 005推断两个字符串是否是变位词 (keep it up)
写一个函数推断两个字符串是否是变位词. 变位词(anagrams)指的是组成两个单词的字符同样,但位置不同的单词.比方说, abbcd和abcdb就是一对变位词 这也是简单的题. 我们能够排序然后对照 ...
- [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 ...
- 【easy】438.Find All Anagrams in a String 找出字符串中所有的变位词
Input: s: "abab" p: "ab" Output: [0, 1, 2] Explanation: The substring with start ...
- [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 ...
随机推荐
- 算法精解(C语言描述) 第5章 读书笔记
第5章 5.1 单链表 /* -------------------------------- list.h -------------------------------- */ #ifndef L ...
- 整合Spring.net到asp.net网站开发中初探
整合Spring.net到asp.net网站开发中初探 http://www.veryhuo.com 2009-10-21 烈火网 投递稿件 我有话说 Spring提供了一个轻量级的用于构建企业级 ...
- JavaScript引用类型之Array类型一
一.简介 除了Object之外,Array类型恐怕是ECMAScript中最常用的类型了.下面就来分析ECMAScript中的数组与其他语言中的数组的异同性: 1.相同点: (1)他们都是数据的有序列 ...
- Infragistics的介绍以及在ASP.net中使用的总结
Infragistics系列控件是一套很好,很强大的控件,.感觉很好..现在自己做项目也用..却发现网上没有一套中文的教程,中文资料都很少..在这里就把自己的研究心得写下来... 首先安装,一步一步装 ...
- springmvc+mybatis集成配置
简单之美,springmvc,mybatis就是一个很好的简单集成方案,能够满足一般的项目需求.闲暇时间把项目配置文件共享出来,供大家参看: 1.首先我们来看下依赖的pom: <!-- spri ...
- 条件注释+JS实现各版本IE浏览器className
最近又开始忙了,项目中又遇到了可恶的IE Hack问题,各种Hack的看着让自己都觉得恶心,于是决定改造一番. 首先请出条件注释语句: 之前用过的条件注释 <!--[if lt IE 7]> ...
- LaTeX技巧如何拆分源文件并且分别编译
当处理很大的文档时,经常将文件分成若干个部分分别进行编译,这时我们可以使用LATEX所提供的命令 \input \include \includeonly \input{texfile} 文件名只需指 ...
- python+sublime text2中文乱码[Decode error - output not utf-8]
转自: http://blog.sina.com.cn/s/blog_765abd7b0101dtbw.html 学习,记录一下.中文编码真的挺麻烦.抽空把自己的sb3的配置写一些. 该问题让我纠结了 ...
- javascript 数组和字符串的转化
字符串转化为数组 'abcde' -> ['a', 'b', 'c', 'd', 'e'] 简单一点的方法,__String.prototype.split__可以将字符串转化为数组,分隔符为空 ...
- Android中计算时间差的实现方法
今天为“至简天气”增加了一项功能:在启动时根据上次更新数据的时间判断是否有必要更新数据,因为 weather.com.cn 的实况数据貌似是25分钟才会刷新一次,只有在据上次更新的时间达25分钟以上才 ...