寻找最长递增数字子串

阅读更多
    有一个字符串,其中包含了多个数字子串,要求求出最长的递增数字子串,比如,s='asdf1123as456df112365asdfa'中最长递增数字子串是11236.

string="asdfasdfasdf1111112222222356789462124asdfasdfasdfa9874563214756asdfasdfasdfasdfasdfasdfalkjlaskdjflkasdf124578"
s=string.scan(/\d+/)
#t=s[1].split //
#puts t.size
#print t,"\n"
ss=[]
hash={}
max=tt=0
s.each do |t|
    t=t.split //
for i in 0...(t.size)
    if(t[i+1]&&t[i+1]>=t[i])
         ss<max)
            max=tt
            hash[ss.join('')]=max
        end
    else
        ss< 
 


应该会有更简洁的方法的,慢慢再想!!!!

你可能感兴趣的:(Ruby,正则表达式,IDEA)