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

Commit4056779

Browse files
committed
fix global map
1 parent8723380 commit4056779

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

‎basic_algorithm/dp.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,36 +486,37 @@ func wordBreak(s string, wordDict []string) bool {
486486
}
487487
f:=make([]bool,len(s)+1)
488488
f[0] =true
489-
max:=maxLen(wordDict)
489+
max,dict:=maxLen(wordDict)
490490
fori:=1; i <=len(s); i++ {
491491
l:=0
492492
if i - max >0 {
493493
l = i - max
494494
}
495495
forj:= l; j < i; j++ {
496-
if f[j] &&inDict(s[j:i]) {
496+
if f[j] &&inDict(s[j:i],dict) {
497497
f[i] =true
498-
break
498+
break
499499
}
500500
}
501501
}
502502
return f[len(s)]
503503
}
504504

505-
vardict =make(map[string]bool)
506505

507-
funcmaxLen(wordDict []string)int {
506+
507+
funcmaxLen(wordDict []string) (int,map[string]bool) {
508+
dict:=make(map[string]bool)
508509
max:=0
509510
for_,v:=range wordDict {
510511
dict[v] =true
511512
iflen(v) > max {
512513
max =len(v)
513514
}
514515
}
515-
return max
516+
return max,dict
516517
}
517518

518-
funcinDict(sstring)bool {
519+
funcinDict(sstring,dictmap[string]bool)bool {
519520
_,ok:= dict[s]
520521
return ok
521522
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp