Java Solution, 3ms


  • 0
    M
    public class Solution {
        public int titleToNumber(String s) {
            int sum = 0, n=1;
            for (int i=s.length()-1; i>=0; i--) {
                char x = s.charAt(i);
                sum += n*(x-64);
                n *= 26;
            }
            return sum;
        }
    }

Log in to reply
 

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