I need help T-T


  • 0
    F

    Hi there,
    I'm a beginner in programming. And I'm trying to write code in Python. When I tried to solve the "longest substring without repeating characters", my code failed at a case of "s='bbbbb'".
    it said the output was 3 and the expected answer was 1.
    However, I tried my code in my own idle, it did show the answer was 1.
    I was totally confused. (T-T)
    If anyone would like to help me, I will be very appreciated. Thank you!
    Here is my code:
    '''
    class Solution(object):
    global t1
    t1=[0]
    def lengthOfLongestSubstring(self, s):
    t=[]
    for i in range(len(s)):
    if s[i] not in t:
    t.append(s[i])
    if i==len(s)-1:
    t1.append(len(t))
    else:
    t1.append(len(t))

                if (len(s)-1-i)>max(t1):
                    for k in range(i):
                        if s[k]==s[i]:
                            t=[]                        
                            Solution.lengthOfLongestSubstring(self,s[k+1:])
        return max(t1)
    

    s="bbbbb"

    a=Solution()

    print(a.lengthOfLongestSubstring(s))

    '''


  • 0
    F
    This post is deleted!

  • 0
    F

    alt text

    alt text


Log in to reply
 

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