Ruby 6 lines Solution


  • 0
    L
    def find_substring_in_wrapround_string(p)
        map = Hash.new(0)
        count = 0
        (0...p.length).each do |i|
            count = (i == 0 || (p[i].ord - p[i - 1].ord) % 26 == 1) ? count + 1 : 1
            map[p[i]] = [map[p[i]], count].max
        end
        return map.values.inject(0) {|sum, n| sum += n}
    end
    

Log in to reply
 

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