@@ -0,0 +1,2355 @@
+package leetcode.course_schedule_ii;%0A%0Aimport java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.LinkedList;%0Aimport java.util.Map;%0Aimport java.util.Queue;%0Aimport java.util.Set;%0A%0Apublic class Solution %7B%0A    public int%5B%5D findOrder(int numCourses, int%5B%5D%5B%5D prerequisites) %7B%0A        Map%3CInteger, Set%3CInteger%3E%3E mapForward = new HashMap%3CInteger, Set%3CInteger%3E%3E();%0A        Map%3CInteger, Set%3CInteger%3E%3E mapBackward = new HashMap%3CInteger, Set%3CInteger%3E%3E();%0A        Set%3CInteger%3E allCourses = new HashSet%3CInteger%3E();%0A        int%5B%5D ret = new int%5BnumCourses%5D;%0A        int retIdx = 0;%0A        for(int i = 0; i %3C numCourses; i++)%7B%0A            allCourses.add(i);%0A        %7D%0A        if(prerequisites == null) return new int%5B%5D%7B%7D;%0A        for(int%5B%5D prerequisite : prerequisites)%7B%0A            if(prerequisite%5B0%5D == prerequisite%5B1%5D) return new int%5B%5D%7B%7D;%0A            Set%3CInteger%3E s;%0A%0A            s = mapBackward.get(prerequisite%5B0%5D);%0A            if(s == null)%7B%0A                s = new HashSet%3CInteger%3E();%0A                mapBackward.put(prerequisite%5B0%5D, s);%0A            %7D%0A            s.add(prerequisite%5B1%5D);%0A%0A            s = mapForward.get(prerequisite%5B1%5D);%0A            if(s == null)%7B%0A                s = new HashSet%3CInteger%3E();%0A                mapForward.put(prerequisite%5B1%5D, s);%0A            %7D%0A            s.add(prerequisite%5B0%5D);%0A        %7D%0A        Queue%3CInteger%3E queue = new LinkedList%3CInteger%3E();%0A        for(int x : mapForward.keySet())%7B%0A            Set%3CInteger%3E s = mapBackward.get(x);%0A            if(s == null %7C%7C s.size() == 0)%7B%0A                queue.offer(x);%0A                allCourses.remove(x);%0A                ret%5BretIdx++%5D = x;%0A            %7D%0A        %7D%0A        while(!queue.isEmpty())%7B%0A            int x = queue.remove();%0A            Set%3CInteger%3E s = mapForward.get(x);%0A            if(s != null)%7B%0A                for(int y : s)%7B%0A                    Set%3CInteger%3E s2 = mapBackward.get(y);%0A                    s2.remove(x);%0A                    if(s2.isEmpty())%7B%0A                        queue.offer(y);%0A                        allCourses.remove(y);%0A                        ret%5BretIdx++%5D = y;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        for(Set%3CInteger%3E s : mapBackward.values())%7B%0A            if(!s.isEmpty()) return new int%5B%5D%7B%7D;%0A        %7D%0A        for(int x : allCourses)%7B%0A            ret%5BretIdx++%5D = x;%0A        %7D%0A        return ret;%0A    %7D%0A%7D

Add java solution for 210. Course Schedule II