일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 밴픽
- Python Code
- 30. Substring with Concatenation of All Words
- Generator
- 109. Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- DWG
- Regular Expression
- Python Implementation
- Convert Sorted List to Binary Search Tree
- Protocol
- Class
- shiba
- concurrency
- 715. Range Module
- t1
- Substring with Concatenation of All Words
- 프로그래머스
- 시바견
- data science
- Python
- Decorator
- 운영체제
- iterator
- 파이썬
- kaggle
- attribute
- LeetCode
- 43. Multiply Strings
- 컴퓨터의 구조
Archives
- Today
- Total
Scribbling
LeetCode: 207. Course Schedule 본문
위상정렬을 이용한다.
class Solution:
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
indegrees = [0] * numCourses
graph = [[] for _ in range(numCourses)]
for v, u in prerequisites:
graph[u].append(v)
indegrees[v] += 1
q = []
for node, indegree in enumerate(indegrees):
if indegree == 0:
q.append(node)
while q:
u = q.pop()
for v in graph[u]:
indegrees[v] -= 1
if indegrees[v] == 0:
q.append(v)
for node, indegree in enumerate(indegrees):
if indegree != 0:
return False
return True
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 8. String to Integer (atoi) (0) | 2021.08.16 |
---|---|
LeetCode: 6. ZigZag Conversion (0) | 2021.08.16 |
LeetCode: 1584. Min Cost to Connect All Points (0) | 2021.08.13 |
LeetCode: 5. Longest Palindromic Substring (0) | 2021.08.12 |
LeetCode: 787. Cheapest Flights Within K Stops (0) | 2021.08.12 |