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

DeleteNodeInALinkedList   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A deleteNode() 0 17 4
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