Skip to content

Commit 6c9f161

Browse files
committed
Add solution 24.
1 parent f07a0e4 commit 6c9f161

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)