[LeetCode][171. Excel Sheet Column Number] 2 Approaches: Base Conversion from High to Low and from Low to High
By Long Luo
This article is the solution 2 Approaches: Base Conversion from High to Low and from Low to High of Problem 171. Excel Sheet Column Number.
Intuition
Basiclly, It’s base conversion.
We are familiar base . How do we calculate a number?
From high to low, starting with as , update with the current digit value each time, the update rule is .
If there is a decimal number, encoded as not the arabic number, what’s it?
1 | ans = 0 |
The answer is: .
from High to Low
1 | public int titleToNumber(String columnTitle) { |
from High to Low
1 | public int titleToNumber_base26(String columnTitle) { |
Analysis
- Time Complexity: , is the length of the string .
- Space Complexity: .
All suggestions are welcome.
If you have any query or suggestion please comment below.
Please upvote👍 if you like💗 it. Thank you:-)
Explore More Leetcode Solutions. 😉😃💗