| Total Complexity | 14 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class ZigzagConversion |
||
| 8 | { |
||
| 9 | public static function convert(string $str, int $numRows): string |
||
| 10 | { |
||
| 11 | [$m, $n] = [$numRows, strlen($str)]; |
||
| 12 | if ($m <= 1 || $m >= $n) { |
||
| 13 | return $str; |
||
| 14 | } |
||
| 15 | [$s, $k] = ['', 2 * $m - 2]; |
||
| 16 | for ($i = 0; $i < $m; $i++) { |
||
| 17 | for ($j = $i; $j < $n; $j += $k) { |
||
| 18 | $s .= $str[$j]; |
||
| 19 | if ($i !== 0 && $i !== $numRows - 1) { |
||
| 20 | $t = $j + $k - 2 * $i; |
||
| 21 | if ($t < $n) { |
||
| 22 | $s .= $str[$t]; |
||
| 23 | } |
||
| 24 | } |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | return $s; |
||
| 29 | } |
||
| 30 | |||
| 31 | public static function convert2(string $str, int $numRows): string |
||
| 49 | } |
||
| 50 | } |
||
| 51 |