leetcode 171 Excel Sheet Column Number

来源:互联网 发布:查看php源码 编辑:程序博客网 时间:2024/06/05 15:18

Problem:
给一段字符串,然后求出它对应的数字,’A’-1,’AA’-27

class Solution {public:    int titleToNumber(string s) {        int ans = 0;        for(int i = 0; i < s.size(); i++) {            ans *= 26;            ans += s[i]-'A'+1;        }        return ans;    }};
1 0
原创粉丝点击