Easy to understand 3ms Java solution - 5 lines


  • 0
    K
    public class Solution {
        public int titleToNumber(String s) {
            int sum = 0;
            int len = s.length();
            for(int i = 0;i < len;i++)
                sum += Math.pow(26,len - (i + 1)) * (s.charAt(i) - 'A' + 1);
            return sum;      
        } 
    }
    

Log in to reply
 

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