[LeetCode]#171 Excel Sheet Column Number
1 min readMar 11, 2020
Environment: Python 3.7
Key technique: function ord, 26 Base
Example 1:
Input: "A"
Output: 1
Example 2:
Input: "AB"
Output: 28
Example 3:
Input: "ZY"
Output: 701
Solution:
class Solution:
def titleToNumber(self, s: str) -> int:
result=0
l=len(s)
for i in range (l):
result=result*26+ord(s[i])-64
return result
Submitted result:
Lesson learn:
Use python ord and check base-26.