Java 2m Solution


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

Log in to reply
 

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