题目来源


https://leetcode.com/problems/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

题意分析


Input:a number

Output:a string

Conditions:类似于用26进制,A为第一位,Z为第26位


题目思路


直接对应就好,注意有两个函数:ord()和chr()


AC代码(Python)


 class Solution(object):
def convertToTitle(self, n):
"""
:type n: int
:rtype: str
"""
res = ""
while n:
h = (n - 1) % 26
res = chr(ord('A') + h) + res
n = (n - 1) / 26
return res

[LeetCode]题解(python):118-Excel Sheet Column Title的更多相关文章

  1. LeetCode(168) Excel Sheet Column Title

    题目 Given a positive integer, return its corresponding column title as appear in an Excel sheet. For ...

  2. Leetcode Excel Sheet Column Number (C++) && Excel Sheet Column Title ( Python)

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  3. LeetCode 168. Excel表列名称(Excel Sheet Column Title)

    168. Excel表列名称 168. Excel Sheet Column Title 题目描述 给定一个正整数,返回它在 Excel 表中相对应的列名称. LeetCode168. Excel S ...

  4. 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number

    题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...

  5. 【leetcode】Excel Sheet Column Title

    Excel Sheet Column Title Given a non-zero positive integer, return its corresponding column title as ...

  6. 2016.5.19——Excel Sheet Column Title

    Excel Sheet Column Title 本题收获: 1.由int型转换为整型(string),如何转化, res = 'A'+(n-1)%26和之前由A-z转化为十进制相反,res = s[ ...

  7. Excel Sheet Column Title&&Excel Sheet Column Number

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  8. LeetCode_168. Excel Sheet Column Title

    168. Excel Sheet Column Title Easy Given a positive integer, return its corresponding column title a ...

  9. Excel Sheet Column Title & Excel Sheet Column Number

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  10. 168. Excel Sheet Column Title

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

随机推荐

  1. redis_查找命令

    1:文件名查找 find -name "filename" filename可以用通配符 2:文件内行数查找 在vi模式下 ,刚进入vi 输入:128(linenum)   即能跳 ...

  2. (转)微信公众平台开发之基于百度 BAE3.0 的开发环境搭建(采用 Baidu Eclipse)

    原文传送门(http://blog.csdn.net/bingtianxuelong/article/details/17843111) 版本说明:     V1:         2014-2-13 ...

  3. cms 二级域名修改信息

    \CMS\Collect\PageRes.cs _content = _content.Replace(r.orgurl, newurl); _content = _content.Replace(r ...

  4. POJ 3254 Corn Fields(状压DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13732   Accepted: 7216 Desc ...

  5. HDU 2091 空心三角形(模拟)

    把一个字符三角形掏空,就能节省材料成本,减轻重量,但关键是为了追求另一种视觉效果.在设计的过程中,需要给出各种花纹的材料和大小尺寸的三角形样板,通过电脑临时做出来,以便看看效果.   Input 每行 ...

  6. dragloader.js帮助你在页面原生滚动下实现Pull Request操作

    dragloader.js是一个面向移动Web开发的JavaScript库,帮助开发者在使用页面原生滚动时,模拟上/下拉手势,实现Pull Request操作. 在移动设备上,一般会使用 drag d ...

  7. svn搭建,很简单

    yum install subversion 2015年1月7日15:23:07 我测试的时间 系统是centos6.5 直接yum,centos是可以直接解决apr apr-util 依赖问题,如果 ...

  8. 嵌入式 如何定位死循环或高CPU使用率(linux) 及性能优化

    嵌入式 如何定位死循环或高CPU使用率(linux) ln -s /mnt/nfs/_install/usr/bin/sort /usr/bin/sort awk '{print $1,$2,$14, ...

  9. Nvidia Anisotropic Lighting

    http://http.download.nvidia.com/developer/SDK/Individual_Samples/DEMOS/Direct3D9/HLSL_Aniso.zip Anis ...

  10. PHP 错误与异常 笔记与总结(1)错误(Deprecated,Notice,Warning)

    [常见的错误类型] ① 语法错误 [例1]程序语句结尾少了';' <?php $username = "dee" //少了分号; echo $username; 输出: ( ...