# Reverse Nodes in k-Group

    ListNode* reverseKGroup(ListNode* head, int k) {
int cnt = 0; // 计数
ListNode *sstack[k], *cursor; // 数组栈
ListNode dummy(0), *pre = &dummy, *p = head; // p为待翻转group的第一个节点
while (p) {
cnt = k;
cursor = p;

for (int i=0; i<k; i++) {
if (cursor == NULL) {
return dummy.next;
}
sstack[i] = cursor; // group内节点入栈
cursor = cursor->next;
}

for (int i=k-1; i>=1; i--) { // 翻转group内各节点
sstack[i]->next = sstack[i-1];
}

pre->next = sstack[k-1]; // 一些连接操作
p->next = cursor;
pre = p;
p = p->next;

}
return dummy.next;
}


#### LeetCode 25 Reverse Nodes in k-Group (C,C++,Java,Python)

2015-05-11 19:55:08

#### （Java）LeetCode-25. Reverse Nodes in k-Group

2016-06-02 22:06:36

#### LeetCode 25: Reverse Nodes in k-Group

2015-06-08 20:00:42

#### [Leetcode][python]Reverse Nodes in k-Group

2017-09-05 09:00:36

#### [LeetCode] 025. Reverse Nodes in k-Group (Hard) (C++/Java)

2015-03-05 15:04:52

#### 【LeetCode】Reverse Nodes in k-Group 解题报告

2014-12-17 17:01:26

#### LeetCode -- Reverse Nodes in k-Group

2015-10-30 14:40:19

#### [leetcode] 25. Reverse Nodes in k-Group 解题报告

2016-01-08 10:51:18

#### leetcode-25. Reverse Nodes in k-Group

2016-11-22 10:30:24