Test Failed
Push — master ( 9fb278...55a969 )
by Jinyun
02:11
created

DeleteNodeInALinkedList::deleteNode()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 17
rs 9.9332
cc 4
nc 6
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
use leetcode\util\ListNode;
8
9
class DeleteNodeInALinkedList
10
{
11
    public static function deleteNode(ListNode $head, int $value): ListNode
12
    {
13
        if ($head->val === $value) {
14
            $head = $head->next;
15
        }
16
17
        $prev = $curr = $head;
18
        while ($curr) {
19
            if ($curr->val === $value) {
20
                $prev->next = $curr->next;
21
            } else {
22
                $prev = $curr;
23
            }
24
            $curr = $curr->next;
25
        }
26
27
        return $head;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $head could return the type null which is incompatible with the type-hinted return leetcode\util\ListNode. Consider adding an additional type-check to rule them out.
Loading history...
28
    }
29
}
30