Finding longest substring in alphabetical order

后端 未结 17 1433
刺人心
刺人心 2020-12-06 15:15

EDIT: I am aware that a question with similar task was already asked in SO but I\'m interested to find out the problem in this specific piece of code. I am

17条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 15:40

    s = 'azcbobobegghakl' 
    
    i=1
    subs=s[0]
    subs2=s[0]
    while(i=s[j-1]):
                subs+=s[j]
                j+=1 
            else:
                subs=subs.replace(subs[:len(subs)],s[i])   
                break
    
            if(len(subs)>len(subs2)):
                subs2=subs2.replace(subs2[:len(subs2)], subs[:len(subs)])
        subs=subs.replace(subs[:len(subs)],s[i])
        i+=1
    print("Longest substring in alphabetical order is:",subs2)
    

提交回复
热议问题