Leetcode 171 Excel Sheet Column Number
发布时间:2020-12-13 21:20:32 所属栏目:PHP教程 来源:网络整理
导读:Related to questionExcel 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
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进制 class Solution { public: int titleToNumber(string s) { int res = 0,base = 1; for(int i = s.size()⑴; i >= 0; i--) { res += base*(s[i]+1-'A'); base*=26; } return res; } };
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |