Leetcode#171. Excel Sheet Column Number(Excel表列号--进制转换)

题目

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 

题意

简单题。26进制转换为10进制

Python语言

class Solution(object):
    def titleToNumber(self, s):
        """
        :type s: str
        :rtype: int
        """
        temp="0ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        n = 0;
        for i in range(0, len(s)):
            n = n * 26 + temp.index(s[i]);
        return n;

C++语言

class Solution {
public:
    int titleToNumber(string s) {
        string temp="0ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int n = 0;
        for(int i=0; i26 + temp.find(s[i]);
        }
        return n;
    }
};

你可能感兴趣的:(【LeetCode】,LeetCode)