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

Commit075a57f

Browse files
committed
update: 24
1 parentfa07a98 commit075a57f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
2424
| 17|[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)|[JavaScript](./src/letter-combinations-of-a-phone-number/res.js)| Medium|
2525
| 19|[Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)|[JavaScript](./src/remove-nth-node-from-end-of-list/res.js)| Medium|
2626
| 22|[Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)|[JavaScript](./src/generate-parentheses/res.js)| Medium|
27+
| 24|[swap-nodes-in-pairs](https://leetcode.com/problems/swap-nodes-in-pairs/)|[TypeScript](./src/swap-nodes-in-pairs/res.ts)| Medium|
2728
| 26|[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)|[JavaScript](./src/remove-duplicates-from-sorted-array/res.js)| Easy|
2829
| 27|[Remove Element](https://leetcode.com/problems/remove-element/)|[JavaScript](./src/remove-element/res.js)| Easy|
2930
| 28|[Implement strStr()](https://leetcode.com/problems/implement-strstr/)|[JavaScript](./src/implement-strstr/res.js)| Easy|

‎src/swap-nodes-in-pairs/res.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Definition for singly-linked list.
3+
*/
4+
//@ts-ignore
5+
classListNode{
6+
val:number
7+
next:ListNode|null
8+
constructor(val?:number,next?:ListNode|null){
9+
this.val=(val===undefined ?0 :val)
10+
this.next=(next===undefined ?null :next)
11+
}
12+
}
13+
14+
functionswapPairs(head:ListNode|null):ListNode|null{
15+
if(!head?.next){
16+
returnhead;
17+
}
18+
19+
constresult=head.next;
20+
letprevPoint=null;
21+
letcurrentPoint:ListNode|null=head;
22+
while(currentPoint){
23+
constnextPoint=currentPoint.next;
24+
constrestPoint=nextPoint?.nextasListNode|null;
25+
26+
if(nextPoint){
27+
currentPoint.next=restPoint;
28+
nextPoint.next=currentPoint;
29+
if(prevPoint){
30+
prevPoint.next=nextPoint;
31+
}
32+
prevPoint=currentPoint;
33+
currentPoint=restPoint;
34+
}else{
35+
break;
36+
}
37+
}
38+
39+
returnresult;
40+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp