Total Complexity | 7 |
Total Lines | 30 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class ExcelSheetColumnNumber |
||
8 | { |
||
9 | public static function titleToNumber(string $title): int |
||
10 | { |
||
11 | if (empty($title)) { |
||
12 | return 0; |
||
13 | } |
||
14 | [$ans, $n] = [0, strlen($title)]; |
||
15 | for ($i = 0; $i < $n; $i++) { |
||
16 | $ans *= 26; |
||
17 | $ans += ord(strtoupper($title[$i])) - ord('A') + 1; |
||
18 | } |
||
19 | |||
20 | return $ans; |
||
21 | } |
||
22 | |||
23 | public static function titleToNumber2(string $title): int |
||
37 | } |
||
38 | } |
||
39 |