Skip to main content
Back to problems
#171
Easy Algorithms

Excel sheet column number

Math String
67.3% acceptance
Jan 12, 2026
5078
399
Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ...

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn title_to_number(column_title: String) -> i32 {
    let mut result = 0;
    
    for ch in column_title.chars() {
      result = result * 26 + (ch as i32 - 'A' as i32 + 1);
    }
    
    result
  }
}