Test Failed
Push — master ( f38782...f110ed )
by Jinyun
02:42
created

ReverseStringII   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A reverseStr() 0 16 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class ReverseStringII
8
{
9
    public static function reverseStr(string $s, int $k): string
10
    {
11
        if (empty($s) || $k <= 0) {
12
            return '';
13
        }
14
        $n = strlen($s);
0 ignored issues
show
Unused Code introduced by
The assignment to $n is dead and can be removed.
Loading history...
15
        [$m, $n] = [0, strlen($s)];
16
        for (; $m < $n; $m += 2 * $k) {
17
            for ($i = $m, $j = min($m + $k - 1, $n - 1); $i < $j; $i++, $j--) {
18
                $t = $s[$i];
19
                $s[$i] = $s[$j];
20
                $s[$j] = $t;
21
            }
22
        }
23
24
        return $s;
25
    }
26
}
27