C# 3 line solution

  • 0

    ampersat is one character before 'A' in ascii, so I save an add while not being so obscure to use the magical number 64.

    public int TitleToNumber(string s) {
        var sol = 0;
        foreach(char c in s) sol = (c-'@') + sol*26;
        return sol;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.