Java solution with explanation


  • 0
    T

    Twenty-six hexadecimal

        public int titleToNumber(String s) {
            int sum = 0;
            for(int i = s.length()-1; i >= 0; i-- ){
                //convert character into a corresponding number.
                int temp = (int)(s.charAt(i) - 'A')+1;
                sum += temp * Math.pow(26,s.length()-1-i);
            }
            return sum;
        }
    

Log in to reply
 

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