[LeetCode] Excel Sheet Column Number
Posted immjc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] 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
给定Excel的表格标题,求相对应的列号。类似于进制转换,每一位的进制位为26。对给定字符串从右向左进行累加即可。
class Solution { public: int titleToNumber(string s) { int sum = 0; int t = 0; for (int i = s.size() - 1; i >= 0; i--) { sum += ((s[i] - ‘A‘ + 1) * pow(26, t++)); } return sum; } }; // 3 ms
以上是关于[LeetCode] Excel Sheet Column Number的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode171:Excel Sheet Column Number
[leetcode] 171. Excel Sheet Column Number
leetcode-Excel Sheet Column Title
LeetCode 168. Excel Sheet Column Title