Why did I get TypeError: object of type 'int' has no len()?


  • 0
    Z
    class Solution(object):
        def findOrder(self, numCourses, prerequisites):
            """
            :type numCourses: int
            :type prerequisites: List[List[int]]
            :rtype: List[int]
            """
            adj=self._getAdjList(numCourses, prerequisites)
            order=[]
            stack=[]
            for i,list in enumerate(adj):
                if not list:
                    stack.append(i)
            while stack:
                v=stack.pop()
                order.append(v)
                for i,list in enumerate(adj):
                    if not list:
                        continue
                    if v in list:
                        list.remove(v)
                        if not list:
                            stack.append(i)
            
            if len(order)<numCourses:
                 return -1
            return order
        
        def _getAdjList(self,numCourses,prerequisites):
            ret=[[]for i in range(numCourses)]
            for c,pre in prerequisites:
                ret[c].append(pre)
            return ret

Log in to reply
 

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