Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd34ae34

Browse files
committed
update: 148
1 parentcf62e5c commitd34ae34

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
8888
| 136|[Single Number](https://leetcode.com/problems/single-number/)|[JavaScript](./src/single-number/res.js)| Easy|
8989
| 137|[Single Number II](https://leetcode.com/problems/single-number-ii/)|[JavaScript](./src/single-number-ii/res.js)| Medium|
9090
| 139|[word-break](https://leetcode.com/problems/word-break/)|[TypeScript](./src/word-break/res.ts)| Medium|
91+
| 148|[sort-list](https://leetcode.com/problems/sort-list/)|[TypeScript](./src/sort-list/res.ts)| Medium|
9192
| 151|[Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/)|[JavaScript](./src/reverse-words-in-a-string/res.js)| Medium|
9293
| 152|[Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/)|[JavaScript](./src/maximum-product-subarray/res.js)| Medium|
9394
| 153|[Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/)|[JavaScript](./src/find-minimum-in-rotated-sorted-array/res.js)| Medium|

‎src/sort-list/res.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Definition for singly-linked list.
3+
*/
4+
classListNode{
5+
val:number
6+
next:ListNode|null
7+
constructor(val?:number,next?:ListNode|null){
8+
this.val=(val===undefined ?0 :val)
9+
this.next=(next===undefined ?null :next)
10+
}
11+
}
12+
13+
functionmerge(start:ListNode|null,end:ListNode|null):ListNode|null{
14+
letresult:ListNode|null=newListNode(0);
15+
letresultPoint=result;
16+
while(start&&end){
17+
if(start.val>end.val){
18+
resultPoint.next=end;
19+
end=end.next;
20+
}else{
21+
resultPoint.next=start;
22+
start=start.next;
23+
}
24+
25+
resultPoint=resultPoint.next;
26+
}
27+
28+
if(start){
29+
resultPoint.next=start;
30+
}else{
31+
resultPoint.next=end;
32+
}
33+
34+
returnresult.next;
35+
}
36+
37+
functionsortWithRange(start:ListNode|null,end:ListNode|null):ListNode|null{
38+
if(!start){
39+
returnstart;
40+
}
41+
if(start.next===end){
42+
start.next=null;
43+
returnstart;
44+
}
45+
46+
letmidPoint:ListNode|null=start;
47+
letendPoint:ListNode|null=start;
48+
while(endPoint!==end){
49+
midPoint=midPoint?.next;
50+
endPoint=endPoint?.next;
51+
52+
if(endPoint!==end){
53+
endPoint=endPoint?.next;
54+
}
55+
}
56+
57+
constleftNode=sortWithRange(start,midPoint);
58+
constrightNode=sortWithRange(midPoint,end);
59+
60+
returnmerge(leftNode,rightNode);
61+
}
62+
63+
functionsortList(head:ListNode|null):ListNode|null{
64+
returnsortWithRange(head,null);
65+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp