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 3bd209c commit 432377fCopy full SHA for 432377f
CATEGORY.md
@@ -22,6 +22,9 @@
22
- 8.哈希表
23
781 523
24
25
+- 9.链表
26
+ 148
27
+
28
* 字符串
29
30
* 排序
src/148-sort-list/index.js
@@ -0,0 +1,30 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val) {
4
+ * this.val = val;
5
+ * this.next = null;
6
+ * }
7
+ */
8
9
+ * @param {ListNode} head
10
+ * @return {ListNode}
11
12
+var sortList = function (head) {
13
+ let slow = head;
14
+ let fast = head;
15
16
+ while (slow) {
17
+ while (fast) {
18
+ if (slow.val > fast.val) {
19
+ const temp = slow.val;
20
+ slow.val = fast.val;
21
+ fast.val = temp;
+ }
+ fast = fast.next;
+ slow = slow.next;
+ fast = slow;
+ return head;
+};
0 commit comments