Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitae8a0f2

Browse files
authored
add js solution for numDistinct
1 parent63b3ede commitae8a0f2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎problems/0115.不同的子序列.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,28 @@ class SolutionDP2:
222222

223223
Go:
224224

225+
#"diff-455cd7b1bde73eb7c1629849fd60cd421f143d714d4fe025166c56dbbe5260fe-224-226-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
226+
```javascript
227+
constnumDistinct= (s,t)=> {
228+
let dp=Array.from(Array(s.length+1), ()=>Array(t.length+1).fill(0));
225229

230+
for(let i=0; i<=s.length; i++) {
231+
dp[i][0]=1;
232+
}
233+
234+
for(let i=1; i<=s.length; i++) {
235+
for(let j=1; j<=t.length; j++) {
236+
if(s[i-1]=== t[j-1]) {
237+
dp[i][j]= dp[i-1][j-1]+ dp[i-1][j];
238+
}else {
239+
dp[i][j]= dp[i-1][j]
240+
}
241+
}
242+
}
243+
244+
return dp[s.length][t.length];
245+
};
246+
```
226247

227248

228249
-----------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp