主页 > 人工智能  > 

【LeetCode】206.反转链表


leetcode链接 206. 反转链表

#include <stdio.h> struct ListNode { int val; struct ListNode* next; }; typedef struct ListNode ListNode; struct ListNode* reverseList1(struct ListNode* head) { if (head != NULL) { ListNode* n1 = NULL; ListNode* n2 = head; ListNode* n3 = n2->next; while (n2 != NULL) { n2->next = n1; n1 = n2; n2 = n3; if (n3 != NULL) { n3 = n3->next; } } return n1; } return NULL; } ListNode* reverseList2(ListNode* head) { if (head) { ListNode* newhead = NULL; ListNode* cur = head; while (cur) { ListNode* next = cur->next; cur->next = newhead; newhead = cur; cur = next; } return newhead; } return NULL; }
标签:

【LeetCode】206.反转链表由讯客互联人工智能栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“【LeetCode】206.反转链表