Last active
May 21, 2023 13:13
-
-
Save mu8086/333ebd95ffcf1db23a405362514c5339 to your computer and use it in GitHub Desktop.
[C] List Reverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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