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. 阶乘后的零