3ms, O(n) Java solution


  • 0
    K
    public int titleToNumber(String s) {
        int col = 0;
        for (int i = 0; i < s.length(); i++) {
            int val = (int) s.charAt(i) - 64;
            if (i == s.length()-1) {
                col+=val;
            } else col+=Math.pow(26, s.length()-1-i)*val;
        }
        return col;
    }

Log in to reply
 

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