【LeetCode】171. Excel Sheet Column Number

原题链接:https://leetcode.com/problems/excel-sheet-column-number/description/

题目要求:

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 Sheet Column Title的关联问题,上个问题想明白了自然就都明白了。

1 class Solution {
2 public:
3     int titleToNumber(string s) {
4         int result = 0;
5         for (int i = 0; i < s.size(); result = result * 26 + (s.at(i) - 'A' + 1), i++);
6         return result;
7     }
8 };

 

posted on 2017-07-30 16:27  小言大妖  阅读(127)  评论(0)    收藏  举报