QUESTION

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

FIRST TRY

string与数字的转换要借助char

class Solution {
public:
    int titleToNumber(string s) {
        int ret = 0;
        char ch;
        for(int i = 0; i < s.length(); i++)
        {
            ch = s[i]; //string to char
            ret = ret*26 + ch - 'A' + 1;
        }
        return ret;
    }
};

 

相关文章:

  • 2021-08-20
  • 2021-11-07
  • 2022-12-23
  • 2021-10-27
  • 2021-05-29
猜你喜欢
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2021-07-05
  • 2021-08-10
相关资源
相似解决方案