Leetcode - Sqrt(x)
Leetcode - N-ary Tree Level Order Traversal

Leetcode - Excel Sheet Column Number

violet posted @ May 10, 2020 02:13:54 AM in 算法 with tags Algorithm Golang Math , 210 阅读

https://leetcode.com/problems/excel-sheet-column-number/

Given a column title as appear in an Excel sheet, return its corresponding column number.

For example:

    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28 
    ...

Example 1:

Input: "A"
Output: 1

 

func titleToNumber(s string) int {
    count := 1
    result := 0
    for i := len(s)-1; i >= 0; i-- {
        num := int(s[i] - 'A') + 1
        result += num * count
        count *= 26
    }
    return result
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter