7/29/2020

[LeetCode] 171. Excel Sheet Column Number

Problem : https://leetcode.com/problems/excel-sheet-column-number/

This problem equals to convert 27 based number to 10 based number.

from functools import reduce

class Solution:
    def titleToNumber(self, s: str) -> int:
        return reduce(lambda x, y: x * 26 + ord(y) - ord('A') + 1, s, 0)

No comments:

Post a Comment