题目描述:

  给出字符串S和字符串T,计算S的不同的子序列中T出现的个数。

  子序列字符串是原始字符串通过删除一些(或零个)产生的一个新的字符串,并且对剩下的字符的相对位置没有影响。(比如,“ACE”“ABCDE”的子序列字符串,而“AEC”不是)。

样例

  给出S = "rabbbit", T = "rabbit"

  返回 3

动态规划想不明白,用递归做的。

 public class Solution {
public int num = 0; /**
* @param word1 & word2: Two string.
* @return: The minimum number of steps.
*/
public int numDistinct(String S, String T) {
// write your code here
find(S,T,0,0);
return num;
} public void find(String S,String T,int index,int from){
if(index == T.length()){
num++;
return;
} for(int i=from;i<S.length();i++){ if(S.charAt(i) == T.charAt(index))
find(S,T,index+1,i+1);
}
}
}

LintCode-不同的子序列的更多相关文章

  1. lintcode 最长上升连续子序列 II(二维最长上升连续序列)

    题目链接:http://www.lintcode.com/zh-cn/problem/longest-increasing-continuous-subsequence-ii/ 最长上升连续子序列 I ...

  2. C++版 - Lintcode 77-Longest Common Subsequence最长公共子序列(LCS) - 题解

    版权声明:本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - L ...

  3. LintCode 77: 最长公共子序列

    public class Solution { /** * @param A, B: Two string. * @return: the length of the longest common s ...

  4. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  5. [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列

    Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...

  6. lintcode:最长公共子序列

    题目 最长公共子序列 给出两个字符串,找到最长公共子序列(LCS),返回LCS的长度. 样例 给出"ABCD" 和 "EDCA",这个LCS是 "A& ...

  7. lintcode:最长上升子序列

    题目 最长上升子序列 给定一个整数序列,找到最长上升子序列(LIS),返回LIS的长度. 样例 给出[5,4,1,2,3],这个LIS是[1,2,3],返回 3 给出[4,2,4,5,3,7],这个L ...

  8. lintcode 中等题 :Maximum Product Subarray 最大连续乘积子序列

    题目 乘积最大子序列 找出一个序列中乘积最大的连续子序列(至少包含一个数). 样例 比如, 序列 [2,3,-2,4] 中乘积最大的子序列为 [2,3] ,其乘积为6. 解题  法一:直接暴力求解 时 ...

  9. lintcode :最长上升连续子序列

    题目: 最长上升连续子序列 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到右的序列.) 样例 ...

  10. lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)

    Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...

随机推荐

  1. 从零开始Unity3D游戏开发【1 常用快捷键】

    Unity3D近两年起来的很快.自己对游戏一直很有兴趣,所以想找机会转游戏开发.目的之一是赚钱,目的之二是完成自己的小梦想. Unity3D的人才还是紧缺的,招聘网站上各个公司真敢拿着钱砸.让.NET ...

  2. xcode - 移动手势

    #import "ViewController.h" @interface ViewController () /** 创建一个UIView */ @property(nonato ...

  3. 官网下载旧版本的Xcode

    1.登录“苹果开发者中心”——>“SDKs” 2.点击“Xcode” 3.点击页面顶部的“Download” 4.点击页面左下方的“additional tools”,这样就可以查询到各个Xco ...

  4. WCF Service Configuration Editor的使用

    原文:http://www.cnblogs.com/Ming8006/p/3772221.html 通过WCF Service Configuration Editor的配置修改Client端 参考 ...

  5. 使用VisualStudio发布ASP.NET网站

    1.右击网站点击“发布网站” 2.选择或导入发布配置文件.→新建配置文件. 3.输入名称test.→点击确定. 4.发布方法选择文件系统. 5.选择目标位置.→点击下一步 6.文件发布选项选择三个选项 ...

  6. Unity3D移植到自己的Android程序

    用Unity3D开发需要把动画效果移植到现有的APP上面.Unity for Android 比较特殊,Unity for IOS 打包是将XCODE工程直接交给开发者,开发者可以在工程的基础上继续添 ...

  7. Redhat Linux内核升级全记录(转)

        http://www.sina.com.cn 2001/06/15 15:38 中国电脑教育报 李红   Redhat Linux因为比较容易上手,所以用户很多.它系统配置完善,预装了丰富的应 ...

  8. android小知识之意图(intent)

    android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity  B ...

  9. C++可变参数的另一种实现

    大家熟知的C库函数printf函数就是一个可变参数函数,它是怎么实现的呢?不过他实现是有条件的,必须函数参数的入栈顺序为从右向左的顺序,也即函数的形参,在函数调用之前,必须是最右边的参数先入栈,并且参 ...

  10. QT中静态库的生成与使用——创建共享库代码,附例子

    一. 静态库的生成    1. 测试目录: lib    2. 源码文件名: mywindow.h, mywindow.cpp, 类MyWindow继承于QPushButton, 并将文字设置为&qu ...