Skip to content

Commit 8f5d0c0

Browse files
authored
Update 0207-course-schedule.md
1 parent d802fdb commit 8f5d0c0

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

dsa-solutions/lc-solutions/0200-0299/0207-course-schedule.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: "This document provides a solution to the Course Schedule problem."
1212
---
1313

1414
## Problem
15-
You are given a total of numCourses courses labeled from 0 to numCourses - 1. You are also given an array prerequisites where prerequisites[i] = [ a<sub> i</sub> , b<sub> i</sub> ] indicates that you must take course b<sub> i</sub> first if you want to take course a<sub> i</sub> .
15+
You are given a total of numCourses courses labeled from 0 to numCourses - 1. You are also given an array prerequisites where $\text{prerequisites[i]} = [ a^i , b^i ]$ indicates that you must take course $b^i$ first if you want to take course $a^i$ .
1616

1717
For example, the pair [0, 1] indicates that to take course 0 you have to first take course 1.
1818
Return `true` if you can finish all courses. Otherwise, return `false`.
@@ -36,10 +36,10 @@ To take course 1 you should have finished course 0, and to take course 0 you sho
3636
```
3737

3838
### Constraints:
39-
- ```1 <= numCourses <= 2000```
40-
- ```0 <= prerequisites.length <= 5000```
41-
- ```prerequisites[i].length == 2```
42-
- ```0 <= ai, bi < numCourses ```
39+
- `1 <= numCourses <= 2000`
40+
- `0 <= prerequisites.length <= 5000`
41+
- ```prerequisites[i].length == 2`
42+
- `0 <= ai, bi < numCourses `
4343
- All the pairs prerequisites[i] are **unique**.
4444
## Solution
4545
The code aims to solve the problem of determining whether it is possible to finish all the given courses without any cyclic dependencies. It uses the topological sort algorithm, specifically Kahn's algorithm, to solve this problem.
@@ -197,16 +197,18 @@ class Solution:
197197

198198
## Complexity Analysis
199199

200-
### Time Complexity: O(N + P)
200+
### Time Complexity: $O(N + P)$
201201

202202
> **Reason**: Where N is the number of courses and P is the number of prerequisites.
203203
204-
### Space Complexity: O(N + P)
204+
### Space Complexity: $O(N + P)$
205205

206-
> **Reason**: We use an adjacency list to store the graph and an array to store the in-degree of each node.
206+
:::note
207+
**Reason**: We use an adjacency list to store the graph and an array to store the in-degree of each node.
208+
:::
207209

208210
## References
209211

210212
- **LeetCode Problem**: [Course Schedule](https://leetcode.com/problems/course-schedule/description/)
211213

212-
- **Leetcode Solutions:** [Course Schedule](https://leetcode.com/problems/course-schedule/solutions/)
214+
- **Leetcode Solutions:** [Course Schedule](https://leetcode.com/problems/course-schedule/solutions/)

0 commit comments

Comments
 (0)