Excel Sheet Column Title LeetCode solution in Python
1class Solution:2def convertToTitle(self, num: int) -> str:3# We make this lookup list, having A-Z in ascending order4alpha = [5chr(x) for x in range(ord("A"), ord("Z") + 1)6] # range(65, 90+1) -> 91-65 = 267res = ""89while num > 0:10res += alpha[11(num - 1) % 2612] # since 0 indexed list, num-1 % 26 gives the index of ch in alpha13num = (num - 1) // 2614return res[::-1]