Thinking process

public class Solution {
    public static final int NUMBER_OF_DIFF_LETTERS = 26;
    public int titleToNumber(String s) {
        char[] c = s.toCharArray();
        int j = 0;
        int result = 0;
        for (int i = c.length - 1; i >= 0; --i) {
            result += Math.pow(NUMBER_OF_DIFF_LETTERS, j) * (c[i] - 'A' + 1);
            j++;
        }

        return result;
    }
}

results matching ""

    No results matching ""