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

 class Solution {
public:
string convertToTitle(int n) {
string s;
while(n){
s = (char)('A'+(n-)%)+s;
n = (n-)/;
}
return s;
}
};

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 Solution {
2 public:
3 int titleToNumber(string s) { //runtime:8ms
4 int ret=0;
5 for(int i=0;i<s.size();i++)ret = ret*26+s[i]-'A'+1;
6 return ret;
7 }
8 };

【LeetCode】168 & 171- Excel Sheet Column Title & Excel Sheet Column Number的更多相关文章

  1. 【LeetCode】168. Excel Sheet Column Title 解题报告(Java & Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 迭代 递归 日期 [LeetCode] 题目地址:https: ...

  2. 【LeetCode】168. Excel Sheet Column Title

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

  3. 【LeetCode】947. Most Stones Removed with Same Row or Column 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetco ...

  4. 【leetcode】947. Most Stones Removed with Same Row or Column

    题目如下: On a 2D plane, we place stones at some integer coordinate points.  Each coordinate point may h ...

  5. 【LeetCode】171. Excel Sheet Column Number

    题目: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, r ...

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

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

  7. 【leetcode】Excel Sheet Column Number

    Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as appea ...

  8. 【leetcode】688. Knight Probability in Chessboard

    题目如下: On an NxN chessboard, a knight starts at the r-th row and c-th column and attempts to make exa ...

  9. 【leetcode】955. Delete Columns to Make Sorted II

    题目如下: We are given an array A of N lowercase letter strings, all of the same length. Now, we may cho ...

随机推荐

  1. Oracle ->> 层级查询语句(hierarchical query)connect by

    Oracle中的Connect By... Start With语句实现了递归查询或者树状查询. Connect By Prior 一方为起始(root)的ID 参考: http://www.360d ...

  2. Can't find bundle for base name ClientMessages, locale zh_CN

    这是个关于JAVA国际化方面的语音包的问题. 提示这个错误信息就是说找不到代码里写的配置文件. 我这个错误发生在导入一个已经存在的项目时发生的. 解决办法:将配置文件*.properties所在的文件 ...

  3. sublime使用

    显示侧板的文件夹: View -> Side Bar 菜单[project]->add folder to  project.把文件夹显示在左边的sidebar上. 安装插件: packa ...

  4. Github原理

    See image below:

  5. VC操作ADO的基本策略

    一.ADO概述 ADO是Microsoft为最新和最强大的数据访问范例 OLE DB 而设计的,是一个便于使用的应用程序层接口.ADO 使您能够编写应用程序以通过 OLE. DB 提供者访问和操作数据 ...

  6. POJ2282:The Counting Problem(数位DP)

    Description Given two integers a and b, we write the numbers between a and b, inclusive, in a list. ...

  7. SpringMVC上传文件以流方式判断类型附常用类型

    // 此类中判断类型所截取的byte 长度暂不确定,请使用者测试过使用 package com.tg.common.other; import com.tg.common.tginterface.TG ...

  8. IO(二)

    package com.bjsxt.io.buffered; import java.io.BufferedInputStream; import java.io.BufferedOutputStre ...

  9. 四大开源协议:BSD、Apache、GPL、LGPL

    参考文献:http://www.fsf.org/licensing/licenses/ 现今存在的开源协议很多,而经过Open Source Initiative组织通过批准的开源协议目前有58种.我 ...

  10. 我的ipad应用备份

    听歌: 网易云音乐,QQ音乐 摄影: CameraConnect,Replay,PhotoBooth,PhotoCollage,画中画相机,Creative Shape, 简拼,玩图,PicsArt, ...