【LeetCode】168 & 171- Excel Sheet Column Title & Excel Sheet Column Number
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的更多相关文章
- 【LeetCode】168. Excel Sheet Column Title 解题报告(Java & Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 迭代 递归 日期 [LeetCode] 题目地址:https: ...
- 【LeetCode】168. Excel Sheet Column Title
题目: Given a positive integer, return its corresponding column title as appear in an Excel sheet. For ...
- 【LeetCode】947. Most Stones Removed with Same Row or Column 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetco ...
- 【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 ...
- 【LeetCode】171. Excel Sheet Column Number
题目: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, r ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number
题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...
- 【leetcode】Excel Sheet Column Number
Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as appea ...
- 【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 ...
- 【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 ...
随机推荐
- 【流媒体】 Android 实时视频编码—H.264硬编码
[流媒體] Android 实时视频编码—H.264硬编码 SkySeraph Apr 4th 2012 Email:skyseraph00@163.com 1 硬编码 & 软编码 硬编码: ...
- USACO Section 4.2: The Perfect Stall
这题关键就在将题转换成最大流模板题.首先有一个原始点,N个cow个点, M个barn点和一个终点,原始点到cow点和barn点到终点的流都为1,而cow对应的barn就是cow点到对应barn点的流, ...
- JS实现 页面提交防刷新等待提示
//关闭等待窗口 function closediv() { //Close Div document.body.removeChild(document.getElementById("b ...
- [原]poj-2524(裸并查集)
题目链接: http://poj.org/problem?id=2524 题意: n个人,m对人宗教相同,输出一共有多少个不同的宗教. 代码如下: #include<iostream> # ...
- WCF约束名称的用法
<!--<endpoint address="" binding="basicHttpBinding" bindingConfiguration=& ...
- 加密解密(7)*PKI基础知识(完整)
PKI 基础知识 摘要 本白皮书介绍了加密和公钥基本结构(PKI)的概念和使用 Microsoft Windows 2000 Server 操作系统中的证书服务的基础知识.如果您还不熟悉加密和公钥技术 ...
- C#图片压缩的实现方法
一般在web应用中,对客户端提交上来的图片肯定需要进行压缩的.尤其是比较大的图片,如果不经过压缩会导致页面变的很大,打开速度比较慢,当然了如果是需要高质量的图片也得需要生产缩略图. 一般在web应用中 ...
- android测试常用的命令介绍
- windows 创建SSH Key
1. 安装git,从程序目录打开 "Git Bash" (百度或用这个连接http://pan.baidu.com/s/1dDJCx9n 下载) 2. 键入命令:ssh-keyge ...
- 二、理解over()函数
1.1.两个order by的执行时机分析函数是在整个sql查询结束后(sql语句中的order by的执行比较特殊)再进行的操作, 也就是说sql语句中的order by也会影响分析函数的执行结果: ...