Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a0ce9e6

Browse filesBrowse files
committed
DP
1 parent 83f1a02 commit a0ce9e6
Copy full SHA for a0ce9e6

File tree

Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-0
lines changed
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def numDistinct(self, s: str, t: str) -> int:
3+
@lru_cache(None)
4+
def dp(i, j):
5+
if j == 0: return 1 # Case t = "", there is a valid subsequence which is empty string.
6+
if i == 0: return 0
7+
ans = dp(i - 1, j)
8+
if s[i-1] == t[j-1]:
9+
ans += dp(i - 1, j - 1)
10+
return ans
11+
12+
return dp(len(s), len(t))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.