为什么我的Python代码需要这么多内存?

时间:2016-08-02 13:05:14

标签: python

请你解释一下为什么我的代码需要如此多的内存

    def new_form(teleport):
        d=dict()
        for i in teleport.split(','):
            h1,h2=i[0],i[1]
            d.setdefault(h1,[]).append(h2)
            d.setdefault(h2,[]).append(h1)
        return d

    def telepor(teleports_string):
        d=new_form(teleports_string)
        queue=[('1','1')]
        while queue:
            current,path=queue.pop(0)
            if len(set(path))==8 and path[-1]=="1":
                return path
            for each in d[current]:
                if (current+each) in path:
                    continue
                queue.append((each,path+each))

输入是字符串类型(“13,14,23,25,34,35,47,56,58,76,68”),我必须找到一种方法抛出此图

0 个答案:

没有答案