We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 584b174 commit d77711eCopy full SHA for d77711e
Data Structures/Linked Lists/Singly Linked List/Reverse_Nodes_in_K_Groups.cpp
@@ -42,12 +42,19 @@ void printList(ListNode* head){
42
ListNode* reverseKGroup(ListNode* head, int k) {
43
ListNode* curr = head;
44
int count = 0;
45
+
46
+ //Take first k group of nodes
47
while (curr != NULL && count != k) {
48
curr = curr->next;
49
count++;
50
}
51
52
if (count == k) {
53
+ //Recursively taking all k group of nodes
54
+ //Passing next group first node as curr
55
curr = reverseKGroup(curr, k);
56
57
+ //Go on reversing the node group using normal reverse steps
58
while (count-- > 0) {
59
ListNode* tmp = head->next;
60
head->next = curr;
0 commit comments