SwapNodesInPairs   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 2
b 0
f 0
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A swapPairs() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
use leetcode\util\ListNode;
8
9
class SwapNodesInPairs
10
{
11
    public static function swapPairs(ListNode $head): ListNode
12
    {
13
        $dummy = new ListNode();
14
        $dummy->next = $head;
15
        $curr = $dummy;
16
17
        while (($a = $curr->next) && ($b = $curr->next->next)) {
18
            $a->next = $b->next;
19
            $curr->next = $b;
20
            $curr->next->next = $a;
21
            $curr = $curr->next->next;
22
        }
23
24
        return $dummy->next;
25
    }
26
}
27