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

Commit20ec965

Browse files
Merge pull requestyoungyangyang04#477 from jackeyjia/patch-7
add js solution for wordBreak
2 parentsa9344c2 +8f7353c commit20ec965

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎problems/0139.单词拆分.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,27 @@ func wordBreak(s string,wordDict []string) bool {
291291
}
292292
```
293293

294+
Javascript:
295+
```javascript
296+
constwordBreak= (s,wordDict)=> {
297+
298+
let dp=Array(s.length+1).fill(false);
299+
dp[0]=true;
300+
301+
for(let i=0; i<=s.length; i++){
302+
for(let j=0; j<wordDict.length; j++) {
303+
if(i>= wordDict[j].length) {
304+
if(s.slice(i- wordDict[j].length, i)=== wordDict[j]&& dp[i- wordDict[j].length]) {
305+
dp[i]=true
306+
}
307+
}
308+
}
309+
}
310+
311+
return dp[s.length];
312+
}
313+
```
314+
294315

295316

296317
-----------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp