码迷,mamicode.com
首页 > 编程语言 > 详细

leetcode Excel Sheet Column Title python

时间:2015-06-14 08:11:21      阅读:220      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!