Finding longest substring in alphabetical order

后端 未结 17 1472
刺人心
刺人心 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

    a lot more looping, but it gets the job done

    s = raw_input("Enter string")
    fin=""
    s_pos =0
    while s_pos < len(s):
        n=1
        lng=" "
        for c in s[s_pos:]:
            if c >= lng[n-1]:
                lng+=c
                n+=1
            else :
                break
        if len(lng) > len(fin):
            fin= lng`enter code here`
        s_pos+=1    
    print "Longest string: " + fin
    

提交回复
热议问题