Skip to content

Commit

Permalink
Merge pull request wind-liang#7 from zhang1pr/master
Browse files Browse the repository at this point in the history
139 & 140 Fix set
  • Loading branch information
wind-liang authored May 9, 2020
2 parents 71b72db + 3dea7e3 commit 673e72f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion leetcode-139-Word-Break.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public boolean wordBreak(String s, List<String> wordDict) {
dp[0] = true;
for (int i = 1; i <= s.length(); i++) {
for (int j = 0; j < i; j++) {
dp[i] = dp[j] && wordDict.contains(s.substring(j, i));
dp[i] = dp[j] && set.contains(s.substring(j, i));
if (dp[i]) {
break;
}
Expand Down
6 changes: 3 additions & 3 deletions leetcode-140-Word-BreakII.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
> dp[0] = true;
> for (int i = 1; i <= s.length(); i++) {
> for (int j = 0; j < i; j++) {
> dp[i] = dp[j] && wordDict.contains(s.substring(j, i));
> dp[i] = dp[j] && set.contains(s.substring(j, i));
> if (dp[i]) {
> break;
> }
Expand Down Expand Up @@ -60,7 +60,7 @@ public List<String> wordBreak(String s, List<String> wordDict) {
for (int i = 1; i <= s.length(); i++) {
temp = new ArrayList<>();
for (int j = 0; j < i; j++) {
if (wordDict.contains(s.substring(j, i))) {
if (set.contains(s.substring(j, i))) {
//得到前半部分的所有情况然后和当前单词相加
for (int k = 0; k < dp.get(j).size(); k++) {
String t = dp.get(j).get(k);
Expand Down Expand Up @@ -116,7 +116,7 @@ public List<String> wordBreak(String s, List<String> wordDict) {
for (int i = 1; i <= s.length(); i++) {
temp = new ArrayList<>();
for (int j = 0; j < i; j++) {
if (wordDict.contains(s.substring(j, i))) {
if (set.contains(s.substring(j, i))) {
for (int k = 0; k < dp.get(j).size(); k++) {
String t = dp.get(j).get(k);
if (t.equals("")) {
Expand Down

0 comments on commit 673e72f

Please sign in to comment.