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 May 19, 2024
1 parent 9c651ef commit cec0b20
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 17 deletions.
1 change: 1 addition & 0 deletions data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
20240519: 207
20240518: 213(todo),198(todo),212(todo),211,338,208(again)
20240517: 347,253(todo),91(todo),217
20240516: 226,98,253(todo)
Expand Down
34 changes: 17 additions & 17 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2024-07-12 -> ['213(todo),198(todo),212(todo),211,338']
2024-07-12 -> ['213(todo),198(todo),212(todo),211,338,208(again)']
2024-07-11 -> ['347,253(todo),91(todo),217']
2024-07-10 -> ['226,98,253(todo)']
2024-07-09 -> ['104,230,102,100']
Expand All @@ -7,7 +7,7 @@
2024-07-06 -> ['371']
2024-07-05 -> ['121,252']
2024-07-04 -> ['125']
2024-06-21 -> ['213(todo),198(todo),212(todo),211,338']
2024-06-21 -> ['213(todo),198(todo),212(todo),211,338,208(again)']
2024-06-20 -> ['347,253(todo),91(todo),217']
2024-06-19 -> ['226,98,253(todo)']
2024-06-18 -> ['104,230,102,100']
Expand All @@ -16,27 +16,27 @@
2024-06-15 -> ['371']
2024-06-14 -> ['121,252']
2024-06-13 -> ['125']
2024-06-08 -> ['213(todo),198(todo),212(todo),211,338']
2024-06-08 -> ['213(todo),198(todo),212(todo),211,338,208(again)']
2024-06-07 -> ['347,253(todo),91(todo),217']
2024-06-06 -> ['226,98,253(todo)']
2024-06-05 -> ['104,230,102,100']
2024-06-04 -> ['105,106']
2024-06-03 -> ['242,235']
2024-06-02 -> ['371']
2024-06-01 -> ['121,252']
2024-05-31 -> ['213(todo),198(todo),212(todo),211,338', '125']
2024-05-31 -> ['213(todo),198(todo),212(todo),211,338,208(again)', '125']
2024-05-30 -> ['347,253(todo),91(todo),217']
2024-05-29 -> ['226,98,253(todo)']
2024-05-28 -> ['104,230,102,100']
2024-05-27 -> ['105,106']
2024-05-26 -> ['213(todo),198(todo),212(todo),211,338', '242,235']
2024-05-26 -> ['213(todo),198(todo),212(todo),211,338,208(again)', '242,235']
2024-05-25 -> ['347,253(todo),91(todo),217', '371']
2024-05-24 -> ['226,98,253(todo)', '121,252']
2024-05-23 -> ['213(todo),198(todo),212(todo),211,338', '104,230,102,100', '125']
2024-05-23 -> ['213(todo),198(todo),212(todo),211,338,208(again)', '104,230,102,100', '125']
2024-05-22 -> ['347,253(todo),91(todo),217', '105,106']
2024-05-21 -> ['213(todo),198(todo),212(todo),211,338', '226,98,253(todo)', '242,235']
2024-05-20 -> ['213(todo),198(todo),212(todo),211,338', '347,253(todo),91(todo),217', '104,230,102,100', '371']
2024-05-19 -> ['213(todo),198(todo),212(todo),211,338', '347,253(todo),91(todo),217', '226,98,253(todo)', '105,106', '121,252']
2024-05-21 -> ['213(todo),198(todo),212(todo),211,338,208(again)', '226,98,253(todo)', '242,235']
2024-05-20 -> ['213(todo),198(todo),212(todo),211,338,208(again)', '347,253(todo),91(todo),217', '104,230,102,100', '371']
2024-05-19 -> ['213(todo),198(todo),212(todo),211,338,208(again)', '347,253(todo),91(todo),217', '226,98,253(todo)', '105,106', '121,252']
2024-05-18 -> ['347,253(todo),91(todo),217', '226,98,253(todo)', '104,230,102,100', '242,235', '125']
2024-05-17 -> ['226,98,253(todo)', '104,230,102,100', '105,106', '371']
2024-05-16 -> ['104,230,102,100', '105,106', '242,235', '121,252']
Expand Down Expand Up @@ -211,7 +211,7 @@
2023-08-29 -> ['131,17', '40', '1448', '113,257']
2023-08-28 -> ['131,17', '90', '199']
2023-08-27 -> ['79', '46', '112']
2023-08-26 -> ['40', '78,39', '572,235', '207']
2023-08-26 -> ['207', '40', '78,39', '572,235']
2023-08-25 -> ['79', '90', '355', '2,146', '404']
2023-08-24 -> ['79', '40', '46', '621', '138']
2023-08-23 -> ['79', '40', '90', '981,143']
Expand All @@ -231,7 +231,7 @@
2023-08-08 -> ['1448', '452', '113,257']
2023-08-07 -> ['33', '208,211', '199', '617']
2023-08-06 -> ['230,105', '875,153', '112']
2023-08-05 -> ['098', '572,235', '853,74', '207', '543,572']
2023-08-05 -> ['207', '098', '572,235', '853,74', '543,572']
2023-08-04 -> ['208,211', '2,146', '739,150,22', '404']
2023-08-03 -> ['230,105', '1448', '138']
2023-08-02 -> ['208,211', '098', '199', '981,143']
Expand All @@ -244,26 +244,26 @@
2023-07-26 -> ['199', '572,235', '138', '452', '113,257']
2023-07-25 -> ['33', '572,235', '2,146', '981,143']
2023-07-24 -> ['572,235', '2,146', '138', '875,153', '567,155', '112']
2023-07-23 -> ['2,146', '138', '981,143', '452', '853,74', '19', '207']
2023-07-23 -> ['207', '2,146', '138', '981,143', '452', '853,74', '19']
2023-07-22 -> ['33', '138', '981,143', '739,150,22', '128,167,3,424', '404', '687']
2023-07-21 -> ['981,143', '452', '875,153', '36,271', '637,653', '1047']
2023-07-20 -> ['33', '452', '853,74', '347']
2023-07-19 -> ['33', '452', '875,153', '739,150,22', '567,155']
2023-07-18 -> ['33', '875,153', '853,74', '19', '113,257']
2023-07-17 -> ['875,153', '853,74', '739,150,22', '128,167,3,424', '104,110', '617']
2023-07-16 -> ['853,74', '739,150,22', '567,155', '36,271', '112']
2023-07-15 -> ['739,150,22', '19', '347', '207', '162', '543,572']
2023-07-15 -> ['207', '739,150,22', '19', '347', '162', '543,572']
2023-07-14 -> ['567,155', '128,167,3,424', '404', '496']
2023-07-13 -> ['567,155', '19', '36,271', '113,257']
2023-07-12 -> ['567,155', '19', '128,167,3,424', '347']
2023-07-11 -> ['19', '128,167,3,424', '36,271', '112']
2023-07-10 -> ['128,167,3,424', '36,271', '347', '113,257', '207', '160,203']
2023-07-10 -> ['207', '128,167,3,424', '36,271', '347', '113,257', '160,203']
2023-07-09 -> ['36,271', '347', '404', '104,110', '687', '1353,21,24']
2023-07-08 -> ['347', '113,257', '112', '637,653', '101']
2023-07-07 -> ['113,257', '207', '162', '067']
2023-07-07 -> ['207', '113,257', '162', '067']
2023-07-06 -> ['113,257', '112', '404']
2023-07-05 -> ['112', '207']
2023-07-04 -> ['112', '207', '404', '104,110', '617']
2023-07-05 -> ['207', '112']
2023-07-04 -> ['207', '112', '404', '104,110', '617']
2023-07-03 -> ['207', '404']
2023-07-02 -> ['404', '162', '543,572', '038']
2023-07-01 -> ['104,110', '687', '674']
Expand Down
20 changes: 20 additions & 0 deletions leetcode_java/src/main/java/LeetCodeJava/BFS/CourseSchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ public boolean canFinish_0_2(int numCourses, int[][] prerequisites) {
}

private boolean dfs(List<Integer> res, Map<Integer, List<Integer>> graph, int[] visited, int course) {

/** NOTE !!!
*
* here we maintain 3 status:
*
* status = 0 : not visited
* status = 1 : visiting
* status = 2 : visited
*
* ->
* So,
* if status == 2, return true directly, since such course already been visited, we should not visit it again
*
* if status = 1, should return false directly, since "it is being visiting now",
* any other progress try to visit the same course at the same time
* means course conflict, -> can't take such course
*
*
* Ref : https://github.com/yennanliu/CS_basics/blob/master/leetcode_python/Breadth-First-Search/course-schedule.py#L44
*/
if (visited[course] == 1) {
return false;
}
Expand Down
73 changes: 73 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,77 @@ public boolean startsWith(String prefix) {
}
}

// LC 207
// dfs ?
// 0930 am
/**
* prerequisites[i] = [ai, bi]
* indicates that
* you must take course "bi" first
* if you want to take course "ai"
*/
public boolean canFinish(int numCourses, int[][] prerequisites) {

if (numCourses == 0 && prerequisites.length == 0){
return true;
}

if (prerequisites.length == 0){
return true;
}

Map<Integer, List<Integer>> map = new HashMap<>();

for (int[] x : prerequisites){
if (!map.containsKey(x[0])){
List<Integer> cur = new ArrayList<>();
cur.add(x[1]);
map.put(x[0], cur);
}else{
List<Integer> cur = map.get(x[0]);
cur.add(x[1]);
map.put(x[0], cur);
}
}

System.out.println("map = " + map);

int[] visited = new int[numCourses];
for (int i = 0; i < numCourses; i++){
visited[i] = 0;
}

for (int i = 0; i < numCourses; i++){
if (! this._help_check(i, visited, map)){
return false;
}
}

return true;
//return Arrays.stream(visited).sum() == numCourses;
}

public boolean _help_check(int courseId, int[] visited, Map<Integer, List<Integer>> map){

System.out.println("---> courseId = " + courseId + " map = " + map + " visited = " + visited);

if (!map.containsKey(courseId)){
return true;
}

for (int val : map.get(courseId)){
if (visited[courseId] == 1){
return false;
}
if (courseId == val){
return false;
}
visited[courseId] = 1;
this._help_check(val, visited, map);
visited[courseId] = 0;
}

return true;
}

}

0 comments on commit cec0b20

Please sign in to comment.