distinct-subsequences Java code
2017-10-26 11:18
337 查看
Given a string S and a string T, count the number of distinct subsequences of T in S.
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,”ACE”is a subsequence of”ABCDE”while”AEC”is not).
Here is an example:
S =”rabbbit”, T =”rabbit”
Return3.
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,”ACE”is a subsequence of”ABCDE”while”AEC”is not).
Here is an example:
S =”rabbbit”, T =”rabbit”
Return3.
public class Solution { public int numDistinct(String S, String T) { if(S == null || T == null || T.length() == 0) return 0; int n = T.length(); int[] dp = new int ; for(int i = 0; i < S.length(); i++) for(int j = n - 1; j >= 0; j--) if(S.charAt(i) == T.charAt(j)) dp[j] = (j == 0 ? 1 : dp[j-1]) + dp[j]; return dp[n-1]; } }
相关文章推荐
- lintcode: Distinct Subsequences
- Leetcode Distinct Subsequences Java
- Distinct Subsequences leetcode java
- LeetCode – Distinct Subsequences Total (Java)
- leetcode — distinct-subsequences
- java.io.IOException: Server returned HTTP response code: 403 for URL: http://的解决办法
- eclipse中debug java code 的5个技巧
- UVa 10069 - Distinct Subsequences
- Java Object 之hashCode
- 【codejava】第八版:第三章 Java基本的程序设计结构[20180103]
- Java code standard
- unique-binary-search-trees Java code
- scramble-string Java code
- LeetCode Distinct Subsequences
- 【codejava】第八版:第十三章 集合[001] [20180104]
- VsCode搭建Java开发环境
- leetcode -- Distinct Subsequences
- Code Hunt Sector 00 Training - Java
- Java code lib aes 加解密
- Java Unreachable code