168 Excel Sheet Column Title Excel表列名称

给定一个正整数,返回它在Excel表中相对应的列名称。
示例:
    1 -> A
    2 -> B
    3 -> C
    ...
    26 -> Z
    27 -> AA
    28 -> AB

详见:https://leetcode.com/problems/excel-sheet-column-title/description/

class Solution {
public:
    string convertToTitle(int n) {
        string res="";
        while(n)
        {
            res=char((n-1)%26+‘A‘)+res;
            n=(n-1)/26;
        }
        return res;
    }
};

参考:https://www.cnblogs.com/ganganloveu/p/4175848.html

原文地址:https://www.cnblogs.com/xidian2014/p/8729437.html

时间: 2024-08-12 04:38:43

168 Excel Sheet Column Title Excel表列名称的相关文章

[leetcode] Excel Sheet Column Title & Excel Sheet Column Number

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 思路: 10进制转26进制 .先求低位再求高位,与10进制转2进制一样. 题解: class Solution

[LeetCode]62. Excel Sheet Column Title Excel列序号

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 Credits:Special thanks to @ifanchu for adding this problem and creating all test

【leetcode】Excel Sheet Column Title & Excel Sheet Column Number (easy)

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 思路: 相当于10进制转26进制.与一般不一样的是10进制对应的是0 - 9.而这个26进制对应的是 A(1)- Z(26), 没有0. 我的代码: strin

168.Excel Sheet Column Title

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 注意:由于下标从1开始而不是从0开始,因此要减一操作. static public string Convert

2016.5.19——Excel Sheet Column Title

Excel Sheet Column Title 本题收获: 1.由int型转换为整型(string),如何转化, res = 'A'+(n-1)%26和之前由A-z转化为十进制相反,res = s[i]-'A'+1.(为什么有+1,-1还有点迷糊,貌似是十进制是0-9,26进制是) 2.十进制到26进制转化 题目: Given a positive integer, return its corresponding column title as appear in an Excel shee

Excel Sheet Column Number & Excel Sheet Column Title

1. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 1 class S

LeetCode OJ:Excel Sheet Column Number(表格列数)

Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 比较简单,类似进制的转换,代码如下: 1 class Solution {

[LeetCode]61. Excel Sheet Column Number Excel列序号

Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 Credits:Special thanks to @ts for addi

leetcode Excel Sheet Column Title python

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 # @ret