Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5024b0f

Browse files
refactor 207
1 parent7efeb87 commit5024b0f

File tree

1 file changed

+0
-28
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-28
lines changed

‎src/main/java/com/fishercoder/solutions/_207.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,6 @@
44
importjava.util.Iterator;
55
importjava.util.Set;
66

7-
/**
8-
* 207. Course Schedule
9-
*
10-
* There are a total of n courses you have to take, labeled from 0 to n - 1.
11-
Some courses may have prerequisites, for example to take course 0 you have to first take course 1,
12-
which is expressed as a pair: [0,1]
13-
Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all courses?
14-
15-
For example:
16-
2, [[1,0]]
17-
There are a total of 2 courses to take.
18-
To take course 1 you should have finished course 0. So it is possible.
19-
20-
2, [[1,0],[0,1]]
21-
There are a total of 2 courses to take.
22-
To take course 1 you should have finished course 0,
23-
and to take course 0 you should also have finished course 1. So it is impossible.
24-
25-
Note:
26-
The input prerequisites is a graph represented by a list of edges, not adjacency matrices. Read more about how a graph is represented.
27-
You may assume that there are no duplicate edges in the input prerequisites.
28-
click to show more hints.
29-
30-
Hints:
31-
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.
32-
Topological Sort via DFS - A great video tutorial (21 minutes) on Coursera explaining the basic concepts of Topological Sort.
33-
Topological sort could also be done via BFS.
34-
*/
357
publicclass_207 {
368

379
publicstaticclassSolution1 {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp