A golang solution


  • 0
    N
    func titleToNumber(s string) int {
        var (
    		r int
    		p int
    	)
    	b := []byte(s)
    
    	for len(b) > 0 {
    		r += (int(b[len(b) - 1] - 'A') + 1) * int(math.Pow(26, float64(p)))
    		p++
    		b = b[:len(b) - 1]
    	}
    	return r
    }

Log in to reply
 

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