We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f07a0e4 commit 6c9f161Copy full SHA for 6c9f161
src/Algorithms/0024.swap-nodes-in-pairs/swap-nodes-in-pairs.php
@@ -0,0 +1,27 @@
1
+/**
2
+ * Definition for a singly-linked list.
3
+ * class ListNode {
4
+ * public $val = 0;
5
+ * public $next = null;
6
+ * function __construct($val) { $this->val = $val; }
7
+ * }
8
+ */
9
+class Solution {
10
+
11
+ /**
12
+ * @param ListNode $head
13
+ * @return ListNode
14
15
+ function swapPairs($head) {
16
+ $cur = $head;
17
+ while ($cur != null && $cur->next != null){
18
19
+ $temp = $cur->val;
20
+ $cur->val = $cur->next->val;
21
+ $cur->next->val = $temp;
22
+ $cur = $cur->next->next;
23
+ }
24
25
+ return $head;
26
27
+}
0 commit comments