Skip to content

Commit

Permalink
update 207 java, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 9, 2024
1 parent 3c3c29d commit c041e94
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@
127| [Word Ladder](https://leetcode.com/problems/word-ladder/)| [Python](./leetcode_python/Breadth-First-Search/word-ladder.py) | _O(n * d)_ | _O(d)_ | Hard/Medium |good basic, check #126 Word Ladder II, `bfs`, `UBER`, `amazon`, `M$`, `fb`| AGAIN************** (9)
130| [Surrounded Regions](https://leetcode.com/problems/surrounded-regions/)| [Python](./leetcode_python/Breadth-First-Search/surrounded-regions.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/BFS/SurroundedRegions.java) | _O(m + n)_ | | Medium |`bfs`, `dfs`,`union find`,good basic, `amazon`| AGAIN*********** (5)
133| [Clone Graph](https://leetcode.com/problems/clone-graph/)| [Python](./leetcode_python/Breadth-First-Search/clone-graph.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Graph/CloneGraph.java) | _O(n)_ | _O(n)_ | Medium |Curated Top 75, good trick, `check #138 Copy List with Random Pointer `,`graph`,`dfs`,`bfs`, `UBER`, `google`,`amazon`,`fb`| AGAIN**************** (9) (MUST)
207| [Course Schedule](https://leetcode.com/problems/course-schedule/)| [Python](./leetcode_python/Breadth-First-Search/course-schedule.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/BFS/CourseSchedule.java) | _O(\|V\| + \|E\|)_ | _O(\|E\|)_ | Medium |Curated Top 75, Topological Sort, backtrack, `good trick`,`dfs`, `bfs` , `amazon`,`fb`| AGAIN**************** (12) (MUST)
207| [Course Schedule](https://leetcode.com/problems/course-schedule/)| [Python](./leetcode_python/Breadth-First-Search/course-schedule.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/BFS/CourseSchedule.java) | _O(\|V\| + \|E\|)_ | _O(\|E\|)_ | Medium |Curated Top 75, Topological Sort, backtrack, `good trick`,`dfs`, `bfs` , `amazon`,`fb`| AGAIN**************** (13) (MUST)
210| [Course Schedule II](https://leetcode.com/problems/course-schedule-ii/)| [Python](./leetcode_python/Breadth-First-Search/course-schedule-ii.py) | _O(\|V\| + \|E\|)_ | _O(\|E\|)_ | Medium |Topological Sort,check `# 207 Course Schedule ` first, `dfs`, `bfs` ,`amazon` ,`fb` | AGAIN********* (9) (again)
261| [Graph Valid Tree](https://leetcode.com/problems/graph-valid-tree/)| [Python](./leetcode_python/Breadth-First-Search/graph-valid-tree.py) | _O(\|V\| + \|E\|)_ | _O(\|V\| + \|E\|)_ | Medium | Curated Top 75, AGAIN, bfs, dfs, grpah, 🔒, `graph`,`quick union`,`union find` ,`google`,`amazon`,`fb`| AGAIN************* (8)
286| [Walls and Gates](https://leetcode.com/problems/walls-and-gates/)| [Python](./leetcode_python/Breadth-First-Search/walls-and-gates.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/BFS/WallsAndGates.java)| _O(m * n)_ | _O(g)_ | Medium | 🔒, `dfs`, `bfs` , `good basic`, `google`,`amazon`,`FB`| AGAIN******** (7)
Expand Down
1 change: 1 addition & 0 deletions data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
20240309: 207(again!!!)
20240308: 152,153(again),190,191,198,200,206(again)
20240307: 139(again),141,143(again)
20240306: 121,124(again),125,128,133(again)
Expand Down
14 changes: 9 additions & 5 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2024-05-03 -> ['207(again!!!)']
2024-05-02 -> ['152,153(again),190,191,198,200,206(again)']
2024-05-01 -> ['139(again),141,143(again)']
2024-04-30 -> ['121,124(again),125,128,133(again)']
Expand All @@ -7,6 +8,7 @@
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-12 -> ['207(again!!!)']
2024-04-11 -> ['152,153(again),190,191,198,200,206(again)']
2024-04-10 -> ['139(again),141,143(again)']
2024-04-09 -> ['121,124(again),125,128,133(again)']
Expand All @@ -16,24 +18,26 @@
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-30 -> ['207(again!!!)']
2024-03-29 -> ['152,153(again),190,191,198,200,206(again)']
2024-03-28 -> ['139(again),141,143(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-22 -> ['207(again!!!)']
2024-03-21 -> ['152,153(again),190,191,198,200,206(again)', '39,48(again),49,53,54']
2024-03-20 -> ['139(again),141,143(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-17 -> ['207(again!!!)', '73,76,79(again),91,25']
2024-03-16 -> ['152,153(again),190,191,198,200,206(again)', '55(again),56,62,70']
2024-03-15 -> ['139(again),141,143(again)']
2024-03-14 -> ['121,124(again),125,128,133(again)']
2024-03-14 -> ['207(again!!!)', '121,124(again),125,128,133(again)']
2024-03-13 -> ['152,153(again),190,191,198,200,206(again)', '100,102,104,105(again)', '39,48(again),49,53,54']
2024-03-12 -> ['139(again),141,143(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-11 -> ['152,153(again),190,191,198,200,206(again)', '121,124(again),125,128,133(again)', '55(again),56,62,70', '1,3,5,4,19']
2024-03-10 -> ['152,153(again),190,191,198,200,206(again)', '139(again),141,143(again)', '100,102,104,105(again)']
2024-03-12 -> ['207(again!!!)', '139(again),141,143(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-11 -> ['207(again!!!)', '152,153(again),190,191,198,200,206(again)', '121,124(again),125,128,133(again)', '55(again),56,62,70', '1,3,5,4,19']
2024-03-10 -> ['207(again!!!)', '152,153(again),190,191,198,200,206(again)', '139(again),141,143(again)', '100,102,104,105(again)']
2024-03-09 -> ['152,153(again),190,191,198,200,206(again)', '139(again),141,143(again)', '121,124(again),125,128,133(again)', '73,76,79(again),91,25']
2024-03-08 -> ['139(again),141,143(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)']
Expand Down
19 changes: 16 additions & 3 deletions leetcode_java/src/main/java/LeetCodeJava/BFS/CourseSchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class CourseSchedule {
// }

// V1
// IDEA : DFS
// IDEA : BFS
// https://leetcode.com/problems/course-schedule/solutions/58775/my-java-bfs-solution/
public boolean canFinish(int numCourses, int[][] prerequisites) {
Map<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
Expand All @@ -81,7 +81,10 @@ public boolean canFinish(int numCourses, int[][] prerequisites) {
}
for (int i = 0; i < prerequisites.length; i++) {
map.get(prerequisites[i][0]).add(prerequisites[i][1]);
indegree[prerequisites[i][1]]++;
// V1
//indegree[prerequisites[i][1]]++;
// V2
indegree[prerequisites[i][1]] += 1;
}
for (int i = 0; i < numCourses; i++) {
if (indegree[i] == 0) {
Expand All @@ -91,9 +94,19 @@ public boolean canFinish(int numCourses, int[][] prerequisites) {
while (!queue.isEmpty()) {
int current = queue.poll();
for (int i : map.get(current)) {
if (--indegree[i] == 0) {

// V1
// if (--indegree[i] == 0) {
// queue.offer(i);
// }

// V2
if (indegree[i] == 1) {
queue.offer(i);
} else {
indegree[i] -= 1;
}

}
count--;
}
Expand Down

0 comments on commit c041e94

Please sign in to comment.