Excel Sheet Column Number (LeetCode)

Question:

https://oj.leetcode.com/problems/excel-sheet-column-number/

 

之前是从数字转换到string,这题要求从string转换回数字。

 

class Solution {
public:
    int titleToNumber(string s) {
        int value = 0;
        
        for (int i = 0; i < s.size(); i++)
        {
            value *= 26;
            value += (s[i] - 'A' + 1);
        }
        
        return value;
    }
};

 

posted @ 2015-01-11 15:48  smileheart  阅读(110)  评论(0编辑  收藏  举报