# Course Schedule I (Leetcode 207)

Problem Link: <https://leetcode.com/problems/course-schedule/>

```python
from collections import defaultdict
class Solution:
    def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
        
        adj=defaultdict(list)
        for i in range(len(prerequisites)):
            adj[prerequisites[i][1]].append(prerequisites[i][0])
        
        indegree=[0 for i in range(numCourses)]
        
        for i in adj:
            for j in adj[i]:
                indegree[j]+=1
        
        q=[]
        for i in range(numCourses):
            if(indegree[i]==0):
                q.insert(0,i)
        ans=[]
        while(len(q)>0):
            for _ in range(len(q)):
                node=q.pop()
                ans.append(node)
                for i in adj[node]:
                    indegree[i]-=1
                    if(indegree[i]==0):
                        q.insert(0,i)
        if(len(ans)==numCourses):
            return True
        else:
            return False
```
