标签:
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
class Solution { public: int titleToNumber(string s) { int n=s.length(); int i,sum=0; for(i=0;i<n;i++) { sum=sum*26+ s[i]-64; } return sum; } };
A的ascii: 65
[leetcode] 171. Excel Sheet Column Number
标签:
原文地址:http://www.cnblogs.com/yuchenkit/p/5300847.html