| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -486,36 +486,37 @@ func wordBreak(s string, wordDict []string) bool { | |||
| 486 | 486 | } | |
| 487 | 487 | f := make([]bool, len(s)+1) | |
| 488 | 488 | f[0] = true | |
| 489 | - max := maxLen(wordDict) | ||
| 489 | + max,dict := maxLen(wordDict) | ||
| 490 | 490 | for i := 1; i <= len(s); i++ { | |
| 491 | 491 | l := 0 | |
| 492 | 492 | if i - max > 0 { | |
| 493 | 493 | l = i - max | |
| 494 | 494 | } | |
| 495 | 495 | for j := l; j < i; j++ { | |
| 496 | - if f[j] && inDict(s[j:i]) { | ||
| 496 | + if f[j] && inDict(s[j:i],dict) { | ||
| 497 | 497 | f[i] = true | |
| 498 | - break | ||
| 498 | + break | ||
| 499 | 499 | } | |
| 500 | 500 | } | |
| 501 | 501 | } | |
| 502 | 502 | return f[len(s)] | |
| 503 | 503 | } | |
| 504 | 504 | ||
| 505 | - var dict = make(map[string]bool) | ||
| 506 | 505 | ||
| 507 | - func maxLen(wordDict []string) int { | ||
| 506 | + | ||
| 507 | + func maxLen(wordDict []string) (int,map[string]bool) { | ||
| 508 | + dict := make(map[string]bool) | ||
| 508 | 509 | max := 0 | |
| 509 | 510 | for _, v := range wordDict { | |
| 510 | 511 | dict[v] = true | |
| 511 | 512 | if len(v) > max { | |
| 512 | 513 | max = len(v) | |
| 513 | 514 | } | |
| 514 | 515 | } | |
| 515 | - return max | ||
| 516 | + return max,dict | ||
| 516 | 517 | } | |
| 517 | 518 | ||
| 518 | - func inDict(s string) bool { | ||
| 519 | + func inDict(s string,dict map[string]bool) bool { | ||
| 519 | 520 | _, ok := dict[s] | |
| 520 | 521 | return ok | |
| 521 | 522 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments