#include class Solution { private: constexpr int numericValue(char c) { return (int) (c-'A'); } public: int titleToNumber(std::string columnTitle) { int value = 0; int length = columnTitle.length(); for (long power = 1, i = length-1; i >= 0; power *= 26, i--) { // value += power; // value += power * numericValue(columnTitle.at(i)); value += power * (1 + numericValue(columnTitle.at(i))); } return value; } };