| Conditions | 6 |
| Paths | 5 |
| Total Lines | 18 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 31 | public static function convert2(string $str, int $numRows): string |
||
| 32 | { |
||
| 33 | [$m, $n] = [$numRows, strlen($str)]; |
||
| 34 | if ($m <= 1 || $m >= $n) { |
||
| 35 | return $str; |
||
| 36 | } |
||
| 37 | [$ans, $key, $step] = [array_fill(0, $m, ''), 0, 1]; |
||
| 38 | for ($i = 0; $i < $n; $i++) { |
||
| 39 | $ans[$key] .= $str[$i]; |
||
| 40 | if ($key === 0) { |
||
| 41 | $step = 1; |
||
| 42 | } elseif ($key === $m - 1) { |
||
| 43 | $step = -1; |
||
| 44 | } |
||
| 45 | $key += $step; |
||
| 46 | } |
||
| 47 | |||
| 48 | return implode('', $ans); |
||
| 49 | } |
||
| 51 |