Java Solution - O(n)

  • 0

    Similar to Decimal-Binary conversion, convert the string of alphabets to the base 26

        public int titleToNumber(String s) {
            int value = 0;
            for(int j=0, i=s.length()-1; i>=0; i--, j++)
                value += ((int)Math.pow(26, j) * (s.charAt(i)-'@'));
            return value;

Log in to reply

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