Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

python报错 TypeError: 'int' object has no attribute '__getitem__'

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        x=str(s)
        if x=="":
            return 0
        maxlength = 1
        a = [i for i in range(1,len(x)+1)]
        for i in range(len(a)):
            a[i]=["" for i in range(0,len(x))]
        for i in range(len(x)):
            abx = 1
            a[i][0]+=x[i]
            for j in range(1,len(a[i])+1):
                if x[i]==x[i-j]  or i-j<0:
                    break
                else:
                    if type(a[i-1][j-1]) != int:
                        a[i][j]=a[i-1][j-1]+a[i][0]
                        abx = abx+1
                        if maxlength < abx:
                            maxlength = abx
                    else: break
        return maxlength

报错图片
在pyCharm上运行没有问题,但在这里就报错了。
希望大神可以帮帮我!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...