Files
2020-08-07 17:06:53 +08:00

34 lines
1021 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [25. Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/description/)
## 题目
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
Example:
```c
Given this linked list: 1->2->3->4->5
For k = 2, you should return: 2->1->4->3->5
For k = 3, you should return: 3->2->1->4->5
```
Note:
- Only constant extra memory is allowed.
- You may not alter the values in the list's nodes, only nodes itself may be changed.
## 题目大意
按照每 K 个元素翻转的方式翻转链表。如果不满足 K 个元素的就不翻转。
## 解题思路
这一题是 problem 24 的加强版problem 24 是两两相邻的元素,翻转链表。而 problem 25 要求的是 k 个相邻的元素翻转链表problem 相当于是 k = 2 的特殊情况。