Get so much trouble with "Special judge: No expected output available."


  • 1
    J

    Yes, I checked this page and this page. But it doesn't provide much help. Is there some general rules for non-available answers? Can't we just return null?

    This is my code, and I want to know its performance:

    public int[] findOrder(int numCourses, int[][] prerequisites) {
    	int[] res = new int[numCourses];
    	if(numCourses==0||prerequisites==null||prerequisites.length==0) return res ;
    	Map<Integer, List<Integer>> map = new HashMap<>();
    	for(int[] pair : prerequisites) {
    		map.computeIfAbsent(pair[1], k -> new ArrayList<>()).add(pair[0]);
    	}
    	Set<Integer> visited = new HashSet<>();
    	Stack<Integer> path = new Stack<>();
    	for(java.util.Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
    		if(!visited.contains(entry.getKey())) {
    			find(entry.getKey(), map, visited, path);
    		}
    	}
    
    	if(path.size()==numCourses) {
    		int i = 0;
    		while(!path.isEmpty()) {
    			res[i++] = path.pop();
    		}
    	}
    	return res;
    }
    
    private void find(int preCourse, Map<Integer, List<Integer>> map, Set<Integer> visited, Stack<Integer> path) {
    	if(visited.contains(preCourse)) {
    		return;
    	}
    	visited.add(preCourse);
    	if(map.containsKey(preCourse)) {
    		for(Integer c : map.get(preCourse)) {
    			find(c, map, visited, path);
    		}
    	}
    	path.push(preCourse);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.