首页 > 编程语言 > 详细

leetcode Excel Sheet Column Title python

时间:2015-06-14 08:10:40      阅读:255      评论:0      收藏:0      [点我收藏+]

Excel Sheet Column Title

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 

python code


class Solution:
# @param {integer} n
# @return {string}
def convertToTitle(self, n):
  a=‘‘
  while n is not 0:
    a+=(chr(((n-1)%26)+65))    #26进制转换问题,跟十进制相似,注意一些细节问题就ok
    n=(n-1)/26
  return a[-1::-1]

leetcode Excel Sheet Column Title python

原文:http://www.cnblogs.com/bthl/p/4574534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!