标签:on() strong excel 问题: exce 函数 get ref 思路
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
思路:
1.进制转化,将十进制转化为每位以A-Z表示的26进制数;
2.Python中,使用ord()函数将字母转化为整数,使用chr()函数将整数转化回字母;
3.注意结果输出的字符串逆序问题;
class Solution(): def convertToTitle(self, n): """ :type n: int :rtype: str """ str_1 = ‘‘ while n: str_1 += chr(ord(‘A‘) + (n - 1) % 26) n = (n - 1) / 26 return str_1[::-1]
相关问题: http://www.cnblogs.com/yancea/p/7504381.html
168. Excel Sheet Column Title (Easy)
标签:on() strong excel 问题: exce 函数 get ref 思路
原文地址:http://www.cnblogs.com/yancea/p/7506456.html