Skip to content
This repository was archived by the owner on Apr 27, 2025. It is now read-only.

Latest commit

 

History

History
35 lines (23 loc) · 550 Bytes

171-Excel-Sheet-Column-Number.md

File metadata and controls

35 lines (23 loc) · 550 Bytes

171. Excel Sheet Column Number

2017-02-20

Related to question Excel Sheet Column Title

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 

Solution

class Solution {
    func titleToNumber(_ s: String) -> Int {
      return  s.unicodeScalars.map({Int($0.value) - 64})
               .reduce(0) { $0 * 26 + $1 }
    }
}