| Total Complexity | 13 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class RotateArray |
||
| 8 | { |
||
| 9 | public static function rotate(array &$nums, int $k): void |
||
| 10 | { |
||
| 11 | if (empty($nums) || $k <= 0) { |
||
| 12 | return; |
||
| 13 | } |
||
| 14 | [$ans, $n] = [[], count($nums)]; |
||
| 15 | foreach ($nums as $i => $num) { |
||
| 16 | $ans[($i + $k) % $n] = $num; |
||
| 17 | } |
||
| 18 | ksort($ans); |
||
| 19 | $nums = $ans; |
||
| 20 | } |
||
| 21 | |||
| 22 | public static function rotate2(array &$nums, int $k): void |
||
| 32 | ); |
||
| 33 | } |
||
| 34 | |||
| 35 | public static function rotate3(array &$nums, int $k): void |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | private static function helper(array &$nums, int $i, int $j): void |
||
| 59 |