mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
Create 171. Excel Sheet Column Number.md
This commit is contained in:
parent
74c2c5ba26
commit
656ff744c0
18
171. Excel Sheet Column Number.md
Normal file
18
171. Excel Sheet Column Number.md
Normal file
@ -0,0 +1,18 @@
|
||||
# [171. Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/description/)
|
||||
# 思路
|
||||
第[168题](https://leetcode.com/problems/excel-sheet-column-title/description/)是将10进制转换为26进制,这题是将26进制转换为10进制.
|
||||
例:将k进制数"abcd"转换为10进制数:`res = d * k^0 + c * k^1 + b * k^2 + a * k^3`.
|
||||
# C++
|
||||
```
|
||||
class Solution {
|
||||
public:
|
||||
int titleToNumber(string s) {
|
||||
int res = 0, multiplier = 1;
|
||||
for(int i = s.size() - 1; i >= 0; i--){
|
||||
res += (int)(s[i] - 'A' + 1) * multiplier;
|
||||
multiplier *= 26;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
```
|
Loading…
Reference in New Issue
Block a user