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 ...
- CAD二次开发(.NET)之PaletteSet和Palette
在CAD中经常用到停靠或浮动的PaletteSet,比如:特性.图层特性管理器.工具选项板等(以下截图来自AutoCAD2010界面). 特性PaletteSet(停靠) 图层特性管理器Palette ...
- Html分组标签
<fieldset> <legend>权限种类</legend></fieldset>
- C#中的ref与out参数(本文仅作为个人笔记)
假如一个方法的参数(形参)是引用类型,那么使用那个参数来进行的任何修改都会改变参数引用的数据.但这里的关键在于,虽然引用的数据发生了变化,但参数本生没有改变——它仍然引用的是一个对象.换句话说,虽然可 ...
- osg项目经验1<MFC+OSG中模型点选效果>
点选主要是重载osg的GUIEventHandler, class CPickHandler : public osgGA::GUIEventHandler{ //自定义回调函数名:CPickHand ...
- BZOJ 4311: 向量( 按时间分治 + 线段树 )
离线, 然后按时间分治, 每个向量都有出现时间[l, r], 直接插入时间线段树(一个向量只会影响O(logN)数量级的线段树节点). 在线段树每个节点弄出凸壳然后二分. 时间复杂度O(Nlog^2N ...
- div模拟滚动条
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="html.aspx.cs&q ...
- Android 仿360桌面小人
首先自定义FloatsWindowView,用于显示动画小人. import android.annotation.SuppressLint; import android.content.Conte ...
- mysql 简单游标
<=====================MYSQL 游标示例=====================> CREATE PROCEDURE `test`.`new_procedure` ...
- codeforces 416B. Appleman and Tree 树形dp
题目链接 Fill a DP table such as the following bottom-up: DP[v][0] = the number of ways that the subtree ...