Skip to content

Instantly share code, notes, and snippets.

@mu8086
Last active May 21, 2023 13:13
Show Gist options
  • Save mu8086/333ebd95ffcf1db23a405362514c5339 to your computer and use it in GitHub Desktop.
Save mu8086/333ebd95ffcf1db23a405362514c5339 to your computer and use it in GitHub Desktop.
[C] List Reverse
int listReverse(struct ListNode** head) {
int node_count = 0;
struct ListNode *tmp = NULL, *walker = *head;
if (walker != NULL) {
node_count = 1;
while (walker->next != NULL) {
tmp = walker->next;
walker->next = tmp->next;
tmp->next = *head;
*head = tmp;
node_count++;
}
}
return node_count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment