Simple solution in Ruby


  • 0
    F
    def title_to_number(s)
        col = 0
    
        # reverse array to start by units 
        s.reverse.split("").each_with_index do |char, power| 
            # power from 0 to s.length - 1
            col = col + (26**power) * (char.ord % "A".ord + 1)
        end
    
        return col
    end

Log in to reply
 

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