Leetcode 171 Excel Sheet Column Number 字符串处理

本质是把26进制转化为10进制

    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28 
 1 class Solution {
 2 public:
 3     int titleToNumber(string s) {
 4         int ans = 0;
 5         for(int i = 0; i<s.size(); ++i){
 6             ans = 26 * ans + s[i] - 'A' + 1;
 7         }
 8         return ans;
 9     }
10 };

 

posted @ 2016-01-16 20:13  Breeze0806  阅读(148)  评论(0编辑  收藏  举报