【LeetCode】168 & 171- Excel Sheet Column Title & Excel Sheet Column Number

时间:2022-03-22 06:56:00

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
【LeetCode】168 & 171- Excel Sheet Column Title & Excel Sheet Column Number
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 & 171- Excel Sheet Column Title & Excel Sheet Column Number的更多相关文章

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

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

  2. 【LeetCode】168&period; Excel Sheet Column Title

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

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

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

  4. 【leetcode】947&period; 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&period; 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 &amp&semi; 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&period; 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&period; 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. Java程序开发&period;邱加永2&period;1节

    by2016.9.8 2.7.1 一维数组 1. 声明 int[] m: char[] c: double[] d:   2. 创建 数组声明之后还不能使用,m = new int[10]: c = ...

  2. MyBatis 入门

    什么是 MyBatis ? MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手工设置参数以及抽取结果集.MyBatis ...

  3. xib中设置控件的圆角

    1.http://my.oschina.net/ioslighter/blog/387991?p=1 利用layer.cornerRadius实现一个圆形的view,将layer.cornerRadi ...

  4. LeetCode Lowest Common Ancestor of a Binary Serach Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  5. 如何在不同编程语言中获取现在的Unix时间戳&lpar;Unix timestamp&rpar;?

    Java time JavaScript Math.round(new Date().getTime()/1000) 之所以除以1000是因为getTime()返回数值的单位是毫秒 Microsoft ...

  6. &lbrack;转&rsqb;linux系统磁盘分区之parted

    转自:http://blog.csdn.net/h249059945/article/details/12668793 对于linux的分区通常可以使用fdisk命令工具和parted工具对于分区表通 ...

  7. pthread&lowbar;create&lpar;&rpar;之前的属性设置

    一.pthread_create()之前的属性设置1.线程属性设置我们用pthread_create函数创建一个线程,在这个线程中,我们使用默认参数,即将该函数的第二个参数设为NULL.的确,对大多数 ...

  8. leetcode283

    public class Solution { public void MoveZeroes(int[] nums) { ; ; i < nums.Length; i++) { //[0, 1, ...

  9. bin&sol;hdfs dfs命令

    appendToFile Usage: hdfs dfs -appendToFile <localsrc> ... <dst> 追加一个或者多个文件到hdfs制定文件中.也可以 ...

  10. &lbrack;javaSE&rsqb; 数据结构(队列)

    队列是一种线性存储结构,他有以下特点: 1.队列中数据是按照“先进先出”方式进出队列的 2.队列只允许在“队首”进行删除操作,在“队尾”进行插入操作 3.队列通常包含两种操作:入队列和出队列 使用数组 ...