[LeetCode]#171 Excel Sheet Column Number

Fatboy Slim
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.

--

--

Fatboy Slim
Fatboy Slim

Written by Fatboy Slim

Interesting in any computer science.

No responses yet