Skip to content

Commit

Permalink
Merge pull request youngyangyang04#134 from KyrieChang/patch-4
Browse files Browse the repository at this point in the history
添加 0024.两两交换链表中的节点.md Java递归版本
  • Loading branch information
youngyangyang04 authored May 15, 2021
2 parents 78f2e76 + 8c2e089 commit 8c3d8aa
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions problems/0024.两两交换链表中的节点.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ public:


Java:

```Java
// 递归版本
class Solution {
public ListNode swapPairs(ListNode head) {
// base case 退出提交
if(head == null || head.next == null) return head;
// 获取当前节点的下一个节点
ListNode next = head.next;
// 进行递归
ListNode newNode = swapPairs(next.next);
// 这里进行交换
next.next = head;
head.next = newNode;

return next;
}
}
```

```java
// 虚拟头结点
class Solution {
Expand Down

0 comments on commit 8c3d8aa

Please sign in to comment.