Skip to content

Commit

Permalink
update 139 java
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 7, 2024
1 parent f04b574 commit 0511855
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
20240307: 139
20240307: 139(again)
20240306: 121,124(again),125,128,133(again)
20240305: 100,102,104,105(again)
20240304: 73,76,79(again),91,25
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
2024-05-01 -> ['139']
2024-05-01 -> ['139(again)']
2024-04-30 -> ['121,124(again),125,128,133(again)']
2024-04-29 -> ['100,102,104,105(again)']
2024-04-28 -> ['73,76,79(again),91,25']
2024-04-27 -> ['55(again),56,62,70']
2024-04-24 -> ['39,48(again),49,53,54']
2024-04-23 -> ['20,21,23,33(again)']
2024-04-22 -> ['1,3,5,4,19']
2024-04-10 -> ['139']
2024-04-10 -> ['139(again)']
2024-04-09 -> ['121,124(again),125,128,133(again)']
2024-04-08 -> ['100,102,104,105(again)']
2024-04-07 -> ['73,76,79(again),91,25']
2024-04-06 -> ['55(again),56,62,70']
2024-04-03 -> ['39,48(again),49,53,54']
2024-04-02 -> ['20,21,23,33(again)']
2024-04-01 -> ['1,3,5,4,19']
2024-03-28 -> ['139']
2024-03-28 -> ['139(again)']
2024-03-27 -> ['121,124(again),125,128,133(again)']
2024-03-26 -> ['100,102,104,105(again)']
2024-03-25 -> ['73,76,79(again),91,25']
2024-03-24 -> ['55(again),56,62,70']
2024-03-21 -> ['39,48(again),49,53,54']
2024-03-20 -> ['139', '20,21,23,33(again)']
2024-03-20 -> ['139(again)', '20,21,23,33(again)']
2024-03-19 -> ['121,124(again),125,128,133(again)', '1,3,5,4,19']
2024-03-18 -> ['100,102,104,105(again)']
2024-03-17 -> ['73,76,79(again),91,25']
2024-03-16 -> ['55(again),56,62,70']
2024-03-15 -> ['139']
2024-03-15 -> ['139(again)']
2024-03-14 -> ['121,124(again),125,128,133(again)']
2024-03-13 -> ['100,102,104,105(again)', '39,48(again),49,53,54']
2024-03-12 -> ['139', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-12 -> ['139(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-11 -> ['121,124(again),125,128,133(again)', '55(again),56,62,70', '1,3,5,4,19']
2024-03-10 -> ['139', '100,102,104,105(again)']
2024-03-09 -> ['139', '121,124(again),125,128,133(again)', '73,76,79(again),91,25']
2024-03-08 -> ['139', '121,124(again),125,128,133(again)', '100,102,104,105(again)', '55(again),56,62,70', '39,48(again),49,53,54']
2024-03-10 -> ['139(again)', '100,102,104,105(again)']
2024-03-09 -> ['139(again)', '121,124(again),125,128,133(again)', '73,76,79(again),91,25']
2024-03-08 -> ['139(again)', '121,124(again),125,128,133(again)', '100,102,104,105(again)', '55(again),56,62,70', '39,48(again),49,53,54']
2024-03-07 -> ['121,124(again),125,128,133(again)', '100,102,104,105(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-06 -> ['100,102,104,105(again)', '73,76,79(again),91,25', '55(again),56,62,70', '1,3,5,4,19']
2024-03-05 -> ['73,76,79(again),91,25', '55(again),56,62,70', '39,48(again),49,53,54']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,37 @@ public class WordBreak {
// }

// V0
// IDEA : BACKTRACK (modify above via GPT)
// IDEA : BFS
// https://github.com/yennanliu/CS_basics/blob/master/leetcode_python/Backtracking/word-break.py
public boolean wordBreak(String s, List<String> wordDict) {
if (s == null || s.length() == 0 || wordDict == null || wordDict.size() == 0) {
return false;
}

Deque<Integer> q = new ArrayDeque<>();
q.offer(0);
boolean[] visited = new boolean[s.length()];

while (!q.isEmpty()) {
int i = q.poll();
if (!visited[i]) {
for (int j = i + 1; j <= s.length(); j++) {
if (wordDict.contains(s.substring(i, j))) {
if (j == s.length()) {
return true;
}
q.offer(j);
}
}
visited[i] = true;
}
}

return false;
}

// V0
// IDEA : BACKTRACK (modified via GPT)
public boolean wordBreak_(String s, List<String> wordDict) {
return check(s, new HashSet<>(wordDict), 0, new Boolean[s.length()]);
}
Expand Down

0 comments on commit 0511855

Please sign in to comment.