Skip to content

Commit 53552c2

Browse files
edit 207
1 parent 70d741e commit 53552c2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Your ideas/fixes/algorithms are more than welcome!
374374
|210|[Course Schedule II](https://leetcode.com/problems/course-schedule-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/CourseScheduleII.java)| O(?)|O(?) | Medium|
375375
|209|[Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/MinimumSizeSubarraySum.java)| O(n)|O(1) | Medium|
376376
|208|[Implement Trie](https://leetcode.com/problems/implement-trie-prefix-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_208.java)| O(n)|O(1) | Medium| Trie
377-
|207|[Course Schedule](https://leetcode.com/problems/course-schedule/)|[Solution](../master/src/main/java/com/fishercoder/solutions/CourseSchedule.java)| O(?)|O(?) | Medium|
377+
|207|[Course Schedule](https://leetcode.com/problems/course-schedule/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_207.java)| O(?)|O(?) | Medium|
378378
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_206.java)| O(n)|O(1) | Easy | Linked List
379379
|205|[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)|[Solution](../../blmaster/src/94fishercoder/algorithms/IsomorphicStrings.java)| O(n)|O(1) | Easy
380380
|204|[Count Primes](https://leetcode.com/problems/count-primes/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_204.java)| O(sqrt(n))|O(n) | Easy

src/main/java/com/fishercoder/solutions/CourseSchedule.java renamed to src/main/java/com/fishercoder/solutions/_207.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
import java.util.Set;
66

77
/**There are a total of n courses you have to take, labeled from 0 to n - 1.
8-
9-
Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]
10-
8+
Some courses may have prerequisites, for example to take course 0 you have to first take course 1,
9+
which is expressed as a pair: [0,1]
1110
Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all courses?
1211
1312
For example:
14-
1513
2, [[1,0]]
16-
There are a total of 2 courses to take. To take course 1 you should have finished course 0. So it is possible.
14+
There are a total of 2 courses to take.
15+
To take course 1 you should have finished course 0. So it is possible.
1716
1817
2, [[1,0],[0,1]]
19-
There are a total of 2 courses to take. To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.
18+
There are a total of 2 courses to take.
19+
To take course 1 you should have finished course 0,
20+
and to take course 0 you should also have finished course 1. So it is impossible.
2021
2122
Note:
2223
The input prerequisites is a graph represented by a list of edges, not adjacency matrices. Read more about how a graph is represented.
@@ -27,7 +28,7 @@
2728
This problem is equivalent to finding if a cycle exists in a directed graph. If a cycle exists, no topological ordering exists and therefore it will be impossible to take all courses.
2829
Topological Sort via DFS - A great video tutorial (21 minutes) on Coursera explaining the basic concepts of Topological Sort.
2930
Topological sort could also be done via BFS.*/
30-
public class CourseSchedule {
31+
public class _207 {
3132

3233
public boolean canFinish(int numCourses, int[][] prerequisites) {
3334
int[] indegree = new int[numCourses];

src/test/java/com/fishercoder/CourseScheduleTest.java renamed to src/test/java/com/fishercoder/_207Test.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package com.fishercoder;
22

3-
import com.fishercoder.solutions.CourseSchedule;
3+
import com.fishercoder.solutions._207;
44
import org.junit.BeforeClass;
55
import org.junit.Test;
66

77
import static junit.framework.Assert.assertEquals;
88

9-
public class CourseScheduleTest {
10-
private static CourseSchedule test;
9+
public class _207Test {
10+
private static _207 test;
1111
private static boolean actual;
1212
private static boolean expected;
1313
private static int[][] prerequisites;
1414
private static int numCourses;
1515

1616
@BeforeClass
1717
public static void setup(){
18-
test = new CourseSchedule();
18+
test = new _207();
1919
}
2020

2121
@Test

0 commit comments

Comments
 (0)