0171.cpp (223B)
1 class Solution { 2 public: 3 int titleToNumber(string columnTitle) { 4 int res = 0; 5 for (char c : columnTitle) { 6 res *= 26; 7 res += c - 'A' + 1; 8 } 9 return res; 10 } 11 };