本文主要是介绍C语言 | Leetcode C语言题解之第86题分隔链表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
struct ListNode* partition(struct ListNode* head, int x) {struct ListNode* small = malloc(sizeof(struct ListNode));struct ListNode* smallHead = small;struct ListNode* large = malloc(sizeof(struct ListNode));struct ListNode* largeHead = large;while (head != NULL) {if (head->val < x) {small->next = head;small = small->next;} else {large->next = head;large = large->next;}head = head->next;}large->next = NULL;small->next = largeHead->next;return smallHead->next;
}
这篇关于C语言 | Leetcode C语言题解之第86题分隔链表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!