[leetcode][PHP实现]Excel Sheet Column Number

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?php
class Solution
{
    public function titleToNumber($s)
    {
        $num = 0;
        $len = strlen($s) - 1;
        for ($i = $len; $i >= 0; $i--)
        {
            $num += (ord($s[$i]) - ord('A') + 1) * (int)pow(26, $len - $i);
        }
        return $num;
    }
}
$solution = new Solution();
echo $solution->titleToNumber("AA");
?>
Licensed under CC BY-NC-SA 4.0