From 1c427ed82a095fb7e632c7a3b89ac2e1ba1255f6 Mon Sep 17 00:00:00 2001 From: haofeng <852172305@qq.com> Date: Sat, 12 Jun 2021 12:06:27 +0800 Subject: [PATCH] =?UTF-8?q?Update=200139.=E5=8D=95=E8=AF=8D=E6=8B=86?= =?UTF-8?q?=E5=88=86.md=20=E6=B7=BB=E5=8A=A0=20python3=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0139.单词拆分.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0139.单词拆分.md b/problems/0139.单词拆分.md index aa729e02..b6a6242e 100644 --- a/problems/0139.单词拆分.md +++ b/problems/0139.单词拆分.md @@ -252,6 +252,23 @@ class Solution { Python: +```python3 +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + '''排列''' + dp = [False]*(len(s) + 1) + dp[0] = True + # 遍历背包 + for j in range(1, len(s) + 1): + # 遍历单词 + for word in wordDict: + if j >= len(word): + dp[j] = dp[j] or (dp[j - len(word)] and word == s[j - len(word):j]) + return dp[len(s)] +``` + + + Go: ```Go