Finding longest substring in alphabetical order

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

    first_seq=s[0]
    break_seq=s[0]
    current = s[0]
    for i in range(0,len(s)-1):
        if s[i]<=s[i+1]:
            first_seq = first_seq + s[i+1]
            if len(first_seq) > len(current):
                current = first_seq
        else:
            first_seq = s[i+1]
            break_seq = first_seq
    print("Longest substring in alphabetical order is: ", current)
    

提交回复
热议问题