【LeetCode】168 - 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 

Solution: 由于A->1,  计算s的末尾时需先减去1

 1 class Solution {
 2 public:
 3     string convertToTitle(int n) {
 4         string s;
 5         while(n){
 6             s =  (char)(‘A‘+(n-1)%26)+s;
 7             n = (n-1)/26;
 8         }
 9         return s;
10     }
11 };
时间: 2024-12-18 03:17:02

【LeetCode】168 - Excel Sheet Column Title的相关文章

【LeetCode】168. 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 简单题 class Solution { public: string convertToTitle(int n) { string str; char

【LeetCode】136.Excel Sheet Column Title

Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Hide Tags Hash Table Bit Manipulation 题目要求是特

【LeetCode】171 - 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 Solution:26进制转十进制,AAA=27*26+1 1 class

【LeetCode】171. 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 简单题,相当于26进制 class Solution { publi

【原创】leetCodeOj --- Excel Sheet Column Title 解题报告

题目地址: https://oj.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 思路: 乍看一下非

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

Leet Code OJ 168. Excel Sheet Column Title [Difficulty: 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 翻译: 给定一个正数,返回它类似Excle中对应的列标题. 分析: 关联问题:"Excel Sheet Column Number"

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

Java for LeetCode 168 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 解题思路: JAVA实现如下: static public String convertToTitle(int n) { S