Slow Java solution


  • 0
    M
    public static int titleToNumber(String s) {
        s = s.toLowerCase();
        int[] arr = new int[s.length()];
        
        for (int i = 0; i < arr.length; i++) {
            arr[i] = s.charAt(i) - 'a' + 1;
        }
        
        int value = 0;
        
        for (int i = 0; i < arr.length; i++) {
            value += (Math.pow(26, arr.length - 1 - i) * arr[i]);
        }
        
        return value;
    }

Log in to reply
 

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