LintCode-不同的子序列
题目描述:
给出字符串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-不同的子序列的更多相关文章
- lintcode 最长上升连续子序列 II(二维最长上升连续序列)
题目链接:http://www.lintcode.com/zh-cn/problem/longest-increasing-continuous-subsequence-ii/ 最长上升连续子序列 I ...
- C++版 - Lintcode 77-Longest Common Subsequence最长公共子序列(LCS) - 题解
版权声明:本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - L ...
- LintCode 77: 最长公共子序列
public class Solution { /** * @param A, B: Two string. * @return: the length of the longest common s ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列
Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...
- lintcode:最长公共子序列
题目 最长公共子序列 给出两个字符串,找到最长公共子序列(LCS),返回LCS的长度. 样例 给出"ABCD" 和 "EDCA",这个LCS是 "A& ...
- lintcode:最长上升子序列
题目 最长上升子序列 给定一个整数序列,找到最长上升子序列(LIS),返回LIS的长度. 样例 给出[5,4,1,2,3],这个LIS是[1,2,3],返回 3 给出[4,2,4,5,3,7],这个L ...
- lintcode 中等题 :Maximum Product Subarray 最大连续乘积子序列
题目 乘积最大子序列 找出一个序列中乘积最大的连续子序列(至少包含一个数). 样例 比如, 序列 [2,3,-2,4] 中乘积最大的子序列为 [2,3] ,其乘积为6. 解题 法一:直接暴力求解 时 ...
- lintcode :最长上升连续子序列
题目: 最长上升连续子序列 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到右的序列.) 样例 ...
- lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)
Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...
随机推荐
- 如何在Objective-C中实现链式语法?
在接触到开源项目 Masonry 后,里面的布局约束的链式写法让我颇感兴趣,就像下面这样: 1 2 3 4 5 6 7 8 UIEdgeInsets padding = UIEdgeInsetsMak ...
- xcode UILabel创建和隐藏
// 创建label UILabel *label = [[UILabel alloc] init]; // 设置显示的文字 label.text = @"Hello world!Hello ...
- Java调用ICTCLAS2015
最近老板让做分词,指定使用ICTCLAS,于是到官网下载了2015,鼓捣了一晚上也没弄出来,百度了一上午还是一头雾水,,幸运的是现在已经弄好了,趁着没忘赶紧写下来. 1.首先解压并找到:2015080 ...
- Ueditor和CKeditor 两款编辑器的使用与配置
一丶ueditor 百度编辑器 1.官方文档,演示,下载地址:http://ueditor.baidu.com/website/index.html 2.百度编辑器的好:Editor是由百度web前端 ...
- C++中常用特殊符号简介(& , * , : , :: , ->)
1."&"一般表示:引用,按位与,取地址. 如: class Complex { public: Complex operator+(Complex &c2) .. ...
- [原创] 小而美 | Mac上鲜为人知,但极大提升效率的小工具
热爱收集实用又好用的软件,工具类软件不在多,发挥作用,提高效率最重要~推荐几个压箱底的藏货 一.Noizio -自然而然的白噪声,专注工作 Noizio是一款OS X 下的白噪音应用,可以让自己觉着是 ...
- 0617 python 基础04
控制流--for 循环 >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 换行输出 >>> for i in range(1 ...
- CSS 基础总结
CSS基础 Doctype 声明位于文档中的最前面,处于 标签之前.告知浏览器的解析器,用什么文档类型 规范来解析这个文档. 在标准模式中,浏览器根据规范呈现页面: 在混杂模式中,页面以一种比较宽松的 ...
- Eclipse启动后一直Initializing Java Tooling (1%)
问题症状: 工作中eclipse崩溃,再次启动后cpu占用99%,状态栏一直显示Initializing Java Tooling: (1%). 解决方案: 删除\workspace\.metadat ...
- file_get_contents post数据
//默认模拟的header头 private function _defaultHeader() { $header = "User-Agent:Mozilla/5.0 (Windows; ...