更新 024.两两交换链表中的节点 排版格式修复

This commit is contained in:
jinbudaily
2023-07-18 15:00:29 +08:00
parent 32bf073bc8
commit 2acceb7474
2 changed files with 23 additions and 759 deletions

View File

@@ -5,7 +5,7 @@
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
## 24. 两两交换链表中的节点
# 24. 两两交换链表中的节点
[力扣题目链接](https://leetcode.cn/problems/swap-nodes-in-pairs/)
@@ -16,9 +16,11 @@
<img src='https://code-thinking.cdn.bcebos.com/pics/24.%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9-%E9%A2%98%E6%84%8F.jpg' width=600 alt='24.两两交换链表中的节点-题意'> </img></div>
## 思路
## 算法公开课
《代码随想录》算法公开课:[帮你把链表细节学清楚! | LeetCode24. 两两交换链表中的节点](https://www.bilibili.com/video/BV1YT411g7br),相信结合视频看本篇题解,更有助于大家对链表的理解。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[帮你把链表细节学清楚! | LeetCode24. 两两交换链表中的节点](https://www.bilibili.com/video/BV1YT411g7br),相信结合视频看本篇题解,更有助于大家对本题的理解**
## 思路
这道题目正常模拟就可以了。
@@ -88,7 +90,8 @@ public:
## 其他语言版本
C:
### C:
```c
/**
* Definition for singly-linked list.
@@ -132,7 +135,7 @@ struct ListNode* swapPairs(struct ListNode* head){
}
```
Java
### Java
```Java
// 递归版本
@@ -176,7 +179,8 @@ class Solution {
}
```
Python
### Python
```python
# 递归版本
# Definition for singly-linked list.
@@ -226,7 +230,8 @@ class Solution:
```
Go
### Go
```go
func swapPairs(head *ListNode) *ListNode {
dummy := &ListNode{
@@ -262,7 +267,8 @@ func swapPairs(head *ListNode) *ListNode {
}
```
Javascript:
### Javascript:
```javascript
var swapPairs = function (head) {
let ret = new ListNode(0, head), temp = ret;
@@ -277,7 +283,7 @@ var swapPairs = function (head) {
};
```
TypeScript
### TypeScript
```typescript
function swapPairs(head: ListNode | null): ListNode | null {
@@ -296,7 +302,7 @@ function swapPairs(head: ListNode | null): ListNode | null {
};
```
Kotlin:
### Kotlin:
```kotlin
fun swapPairs(head: ListNode?): ListNode? {
@@ -316,7 +322,8 @@ fun swapPairs(head: ListNode?): ListNode? {
}
```
Swift:
### Swift:
```swift
func swapPairs(_ head: ListNode?) -> ListNode? {
if head == nil || head?.next == nil {
@@ -337,7 +344,8 @@ func swapPairs(_ head: ListNode?) -> ListNode? {
return dummyHead.next
}
```
Scala:
### Scala:
```scala
// 虚拟头节点
object Solution {
@@ -361,7 +369,8 @@ object Solution {
}
```
PHP:
### PHP:
```php
//虚拟头结点
function swapPairs($head) {
@@ -404,7 +413,7 @@ function swapPairs($head)
}
```
Rust:
### Rust:
```rust
// 虚拟头节点