problem 171.Excel Sheet Column Number sum( (s[i]-'A'+1)*pow(26, i) ) code class Solution { public: int titleToNumber(string s) { int n=0; int ans = 0; while(ns.size()) { ans = ans*26 + (s[n] - 'A' + 1); n++; } return ans; } }; 1
problem
171. Excel Sheet Column Number
sum( (s[i]-'A'+1)*pow(26, i) )
code
class Solution {public:
int titleToNumber(string s) {
int n=0;
int ans = 0;
while(n<s.size())
{
ans = ans*26 + (s[n] - 'A' + 1);
n++;
}
return ans;
}
};
1. Leetcode_Excel Sheet Column Number;