forked from satnaing/astro-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Affected files: .obsidian/workspace.json src/content/blog/leet-code-207-course-schedule.md
- Loading branch information
Showing
2 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,16 @@ | |
"type": "split", | ||
"children": [ | ||
{ | ||
"id": "5c7cbcec3c13656e", | ||
"id": "c93cbacdb763ad00", | ||
"type": "tabs", | ||
"children": [ | ||
{ | ||
"id": "bb9e313e9ec35bc3", | ||
"id": "4077864ed2ae2ddd", | ||
"type": "leaf", | ||
"state": { | ||
"type": "markdown", | ||
"state": { | ||
"file": "src/content/blog/leet-code-74-search-a-2d-matrix.md", | ||
"file": "src/content/blog/leet-code-919-complete-binary tree-inserter.md", | ||
"mode": "source", | ||
"source": false | ||
} | ||
|
@@ -22,16 +22,16 @@ | |
] | ||
}, | ||
{ | ||
"id": "c93cbacdb763ad00", | ||
"id": "67b79f11d4a32e93", | ||
"type": "tabs", | ||
"children": [ | ||
{ | ||
"id": "4077864ed2ae2ddd", | ||
"id": "d3c142ad93a1e3ac", | ||
"type": "leaf", | ||
"state": { | ||
"type": "markdown", | ||
"state": { | ||
"file": "src/content/blog/leet-code-919-complete-binary tree-inserter.md", | ||
"file": "src/content/blog/leet-code-207-course-schedule.md", | ||
"mode": "source", | ||
"source": false | ||
} | ||
|
@@ -103,7 +103,7 @@ | |
"state": { | ||
"type": "backlink", | ||
"state": { | ||
"file": "src/content/blog/leet-code-919-complete-binary tree-inserter.md", | ||
"file": "src/content/blog/leet-code-207-course-schedule.md", | ||
"collapseAll": false, | ||
"extraContext": false, | ||
"sortOrder": "alphabetical", | ||
|
@@ -120,7 +120,7 @@ | |
"state": { | ||
"type": "outgoing-link", | ||
"state": { | ||
"file": "src/content/blog/leet-code-919-complete-binary tree-inserter.md", | ||
"file": "src/content/blog/leet-code-207-course-schedule.md", | ||
"linksCollapsed": false, | ||
"unlinkedCollapsed": true | ||
} | ||
|
@@ -143,7 +143,7 @@ | |
"state": { | ||
"type": "outline", | ||
"state": { | ||
"file": "src/content/blog/leet-code-919-complete-binary tree-inserter.md" | ||
"file": "src/content/blog/leet-code-207-course-schedule.md" | ||
} | ||
} | ||
} | ||
|
@@ -166,11 +166,12 @@ | |
"table-editor-obsidian:Advanced Tables Toolbar": false | ||
} | ||
}, | ||
"active": "4077864ed2ae2ddd", | ||
"active": "d3c142ad93a1e3ac", | ||
"lastOpenFiles": [ | ||
"src/content/blog/leet-code-919-complete-binary tree-inserter.md", | ||
"src/content/blog/leet-code-207-course-schedule.md", | ||
"src/content/blog/leet-code-74-search-a-2d-matrix.md", | ||
"src/content/blog/boj-2529-부등호.md", | ||
"src/content/blog/leet-code-919-complete-binary tree-inserter.md", | ||
"src/content/blog/boj-1339-단어-수학.md", | ||
"src/content/blog/boj-2660-회장뽑기.md", | ||
"src/content/blog/boj-2011-암호코드.md", | ||
|
@@ -195,7 +196,6 @@ | |
"dist/posts/aqua를-이용해-wsl-ubuntu에-neovim을-설치하자.png", | ||
"src/content/blog/manage-cli-program-version-using-aqua-proj-on-windows.md", | ||
"src/content/blog/astro-paper-4.md", | ||
"src/content/blog/implementing-a-worker-thread-pool-in-c.md", | ||
"dist/assets/[email protected]", | ||
"dist/assets/forrest-gump-quote.webp.jpg", | ||
"dist/_astro/[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
author: Gyunseo Lee | ||
title: "LeetCode 207: Course Schedule" | ||
pubDatetime: 2024-07-16T22:37:00+09:00 | ||
modDatetime: 2024-07-16T22:37:00+09:00 | ||
featured: false | ||
draft: false | ||
tags: | ||
- PS | ||
- Algorithms | ||
- DAG | ||
- Topological-Sort | ||
- BFS | ||
- DFS | ||
- LeetCode | ||
- Cycle | ||
- Kahn | ||
- Kosaraju | ||
description: "\b이 문제는 푸는 방법이 엄청 많네요 ㅎㅎ" | ||
ogImage: "" | ||
--- | ||
|
||
## Table of contents | ||
|
||
## 들어가며 | ||
|
||
걸린 시간: 3시간 (50분 안에 못 풀고 cycle 판정에 대해 찾아봤습니다...) | ||
|
||
## 접근 | ||
|
||
WIP | ||
|
||
## 구현 | ||
|
||
WIP | ||
|
||
### DFS + 3 state (from CLRS) | ||
|
||
```python | ||
class Solution: | ||
def get_adjacency_list(self, n, edge_lists): | ||
adj_list = [[] for _ in range(n)] | ||
|
||
for dst, src in edge_lists: | ||
adj_list[src].append(dst) | ||
|
||
return adj_list | ||
|
||
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: | ||
adj_list = self.get_adjacency_list(numCourses, prerequisites) | ||
|
||
# 0: not visited yet, -1: now being processed, 1: had been processed | ||
node_state_list = [0 for _ in range(numCourses)] | ||
|
||
# check cycle | ||
def DFS(cur_node): | ||
|
||
for next_node in adj_list[cur_node]: | ||
if node_state_list[next_node] == 1: | ||
continue | ||
|
||
if node_state_list[next_node] == -1: | ||
return True | ||
|
||
node_state_list[next_node] = -1 | ||
if DFS(next_node): | ||
node_state_list[cur_node] = 1 | ||
return True | ||
|
||
node_state_list[cur_node] = 1 | ||
return False | ||
|
||
for i in range(numCourses): | ||
if node_state_list[i] == 1: | ||
continue | ||
|
||
node_state_list[i] = -1 | ||
if DFS(i): | ||
return False | ||
|
||
return True | ||
|
||
``` | ||
|
||
### Khan 알고리즘 (위상 정렬) | ||
|
||
### Kosaraju 알고리즘 (SCC) |