mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0139.单词拆分.md
This commit is contained in:
@ -254,7 +254,25 @@ Python:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```Go
|
||||||
|
func wordBreak(s string,wordDict []string) bool {
|
||||||
|
wordDictSet:=make(map[string]bool)
|
||||||
|
for _,w:=range wordDict{
|
||||||
|
wordDictSet[w]=true
|
||||||
|
}
|
||||||
|
dp:=make([]bool,len(s)+1)
|
||||||
|
dp[0]=true
|
||||||
|
for i:=1;i<=len(s);i++{
|
||||||
|
for j:=0;j<i;j++{
|
||||||
|
if dp[j]&& wordDictSet[s[j:i]]{
|
||||||
|
dp[i]=true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[len(s)]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user