--- title: 'LeetCode 171. Excel Sheet Column Number' disqus: hackmd --- # LeetCode 171. Excel Sheet Column Number ## Description 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 ... ## Example Input: columnTitle = "ZY" Output: 701 ## Constraints 1 <= columnTitle.length <= 7 columnTitle consists only of uppercase English letters. columnTitle is in the range ["A", "FXSHRXW"]. ## Answer 本題相當於進位轉換,將字元轉成26進位,所以每解一位數就將舊值*26+現值即可。 ```Cin= //2021_11_16 int titleToNumber(char * s) { int ans = 0; while(*s != '\0'){ ans = ans * 26 + (*s - 'A' + 1); s++; } return ans; } ``` ## Link https://leetcode.com/problems/excel-sheet-column-number/ ###### tags: `Leetcode`