728x90
Above is the link to the problem.
Problem
Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.
Example 1
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
Example 2
Input: columnTitle = "ZY"
Output: 701
Analysis
There is 26 alphabet from A to Z.
We calculate A as 1, B as 2 ... Z as 26.
Count digit numbers starting with 0 from the rightmost.
That digit number will be an exponential of 26 and multiply each digit alphabet.
The maximum number of digit number will be the length of columnTitle - 1
I solved this problem by the below code.
This code gets the top 16.3% of time complexity and uses 13.9 MB memory.
728x90
반응형
'Code > LeetCode' 카테고리의 다른 글
[LeetCode] 134. Gas Station (Medium/Python) (0) | 2023.01.14 |
---|---|
[LeetCode] 1833. Maximum Ice Cream Bars (Medium/Python) (0) | 2023.01.08 |
[LeetCode] 169. Majority Element (Easy/Python) (0) | 2022.10.05 |
[LeetCode] 168. Excel Sheet Column Title (Easy/Python) (1) | 2022.09.29 |
[LeetCode] 136. Single number (Easy/Python) (0) | 2022.09.26 |