Simple solution


  • 0
    V
    public int TitleToNumber(string s) {
            var n = s.Length;
            if(string.IsNullOrEmpty(s)) {
                return 0;
            }
            int i = n - 1; int num = 0; int it = 1;
            while(i >= 0)
            {
                num = num + (it * (s[i--] - 64));
                it = it * 26;
            }
            return num;
        }
    

Log in to reply
 

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