Is Judge system of Ruby is no as good as expected ? or is my fault ? Stack too deep but Ok on machine


  • 0
    A
    def can_finish(num_courses, prerequisites)
      graph=[]
      num_courses.times{graph<<[]}
      visited=[0]*num_courses
      prerequisites.each { |cur,pre| graph[pre]<< cur }
      num_courses.times {|i| return false if visited[i]==0 && !dfs(graph,visited,i) }
      true
    end
    
    def dfs(graph,visited,i)
      return false if visited[i]==1
      visited[i]=1
      graph[i].each {|nex| return false if !dfs(graph,visited,nex) }
      visited[i]=2
    end
    

    I have checked my code with others, my code seems no problem.

    If oj system is ok, how should i modify my code?


  • 0
    J

    I got the error on OJ, but OK on my machine.

    The stack too deep occurs on 2000 nodes


  • 0

    Thanks for reporting this. I have just increased the stack memory and your solution should be accepted now.


Log in to reply
 

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