@@ -0,0 +1,1489 @@
+package com.lcclass.topological;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Queue;%0A%0Apublic class CourseSchedule %7B%0A%0A%0A    public boolean canFinish(int numCourses, int%5B%5D%5B%5D prerequisites) %7B%0A        if(prerequisites == null %7C%7C prerequisites.length == 0) return true;%0A        int%5B%5D inDegree = new int%5BnumCourses%5D;%0A        List%3CInteger%3E%5B%5D graph = new ArrayList%5BnumCourses%5D;%0A%0A        for(int i=0; i%3CnumCourses; i++) %7B%0A            graph%5Bi%5D = new ArrayList();%0A        %7D%0A%0A        // build graph%0A        for (int pair%5B%5D : prerequisites) %7B%0A            int pre = pair%5B1%5D;%0A            int cur = pair%5B0%5D;%0A            graph%5Bpre%5D.add(cur);%0A            inDegree%5Bcur%5D++;%0A        %7D%0A        // store courses that have no prerequisites%0A        int visited = 0;%0A        Queue%3CInteger%3E queue = new LinkedList%3C%3E();%0A        for (int i=0; i%3CnumCourses; i++) %7B%0A            if(inDegree%5Bi%5D == 0) %7B%0A                queue.offer(i);%0A            %7D%0A        %7D%0A%0A        // BFS%0A        while(!queue.isEmpty()) %7B%0A            int cur = queue.remove();%0A            // the course is visited%0A            visited++;%0A            // loop current course's prerequisites%0A            for (Integer child : graph%5Bcur%5D) %7B%0A                inDegree%5Bchild%5D--;%0A                // if inDegree is 0, push to the queue%0A                if (inDegree%5Bchild%5D == 0) %7B%0A                    queue.offer(child);%0A                %7D%0A            %7D%0A%0A        %7D%0A%0A        return visited == numCourses;%0A%0A    %7D%0A%7D%0A

Create CourseSchedule.java