Skip to content

Commit 66e4874

Browse files
committed
77
1 parent 1550f1f commit 66e4874

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Day77/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val, next) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.next = (next===undefined ? null : next)
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @return {ListNode}
11+
*/
12+
var swapPairs = function (head) {
13+
14+
let dummy = new ListNode(-1);
15+
dummy.next = head;
16+
let res = dummy;
17+
18+
while (dummy.next && dummy.next.next) {
19+
let p = dummy.next;
20+
let q = dummy.next.next;
21+
22+
dummy.next = q;
23+
p.next = q.next;
24+
q.next = p;
25+
26+
dummy = p;
27+
28+
}
29+
30+
return res.next;
31+
};

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,6 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
172172

173173

174174
|Day 76| [556. Next Greater Element III](https://leetcode.com/problems/next-greater-element-iii/) | [javascript]()|[:memo:](https://leetcode.com/problems/next-greater-element-iii/)|Medium|
175+
176+
177+
|Day 77| [24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [javascript]()|[:memo:](https://leetcode.com/problems/swap-nodes-in-pairs/)|Medium|

0 commit comments

Comments
 (0)