MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / titleToNumber

Function titleToNumber

excel_sheet_column_number_171/solution.go:5–14  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

3import "math"
4
5func titleToNumber(s string) int {
6 var res int
7 var exponent float64
8 for i := len(s) - 1; i > -1; i-- {
9 charNum := int(s[i]-'A') + 1
10 res += charNum * int(math.Pow(float64(26), exponent))
11 exponent++
12 }
13 return res
14}

Callers 1

Test_titleToNumberFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_titleToNumberFunction · 0.68