[JAVA] Trivial / T : O(N), S : O(1)


  • 0
    J
    class Solution {
        public int titleToNumber(String s) {
            char[] chs = s.toCharArray();
            
            int sum = 0;
            for(int i = chs.length - 1; i >= 0; i--){
                sum += (chs[i] - 'A' + 1) * Math.pow(26, chs.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.