Leetcode 171. Excel表列序号 解题思路及C++实现
生活随笔
收集整理的这篇文章主要介绍了
Leetcode 171. Excel表列序号 解题思路及C++实现
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
解题思路:
26进制转10进制。没啥可说的了。
class Solution { public:int get_26(int n){int res = 1;while(n > 0){res *= 26;n--;}return res;}int titleToNumber(string s) {int n = s.length();int res = 0;//逐个处理 s 中的字符for(int i = 0; i < n; i++){res += (s[i] - 'A' + 1) * get_26(n - 1 - i);}return res;} };
总结
以上是生活随笔为你收集整理的Leetcode 171. Excel表列序号 解题思路及C++实现的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Leetcode 168. Excel表
- 下一篇: Leetcode 172. 阶乘后的零