171. Excel Sheet Column Number

class Solution {

    /**
     * @param String $columnTitle
     * @return Integer
     */
    function titleToNumber($columnTitle) {
        $codeTable = ['', ...range('A', 'Z')];
        $targets = str_split($columnTitle);
        $result = 0;
        $digits = 1;
        while(!empty($targets)) {
            $last = array_pop($targets);
            $value = array_search($last, $codeTable);
            $result += $digits * $value;
            $digits *= 26;
        }

        return $result;
    }
}

Last updated