当前位置: 首页> 汽车> 报价 > 链表题目训练

链表题目训练

时间:2025/7/9 11:07:45来源:https://blog.csdn.net/2402_83250773/article/details/142071082 浏览次数: 0次

https://leetcode.cn/problems/remove-linked-li​​​​​​st-elements/description/第一题:移除链表元素

https://leetcode.cn/problems/remove-linked-li​​​​​​st-elements/description/

第二题:反转链表

https://leetcode.cn/problems/reverse-linked-list/description/

 第三题:链表的中间结点

https://leetcode.cn/problems/middle-of-the-linked-list/description/

第四题:合并有序列表

https://leetcode.cn/problems/merge-two-sorted-lists/description/

 

 第五题:链表分割

https://www.nowcoder.com/practice/0e27e0b064de4eacac178676ef9c9d70 

 

/*
struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};*/
class Partition {
public:ListNode* partition(ListNode* pHead, int x) {ListNode* lesshead,*lesstail;lesshead=lesstail=(ListNode*)malloc(sizeof(ListNode));ListNode* greaterhead,*greatertail;greaterhead=greaterhead=(ListNode*)malloc(sizeof(ListNode));while(pHead){if(pHead->val>=x){greatertail->next=pHead;greatertail=greatertail->next;}if(pHead->val<x){lesstail->next=pHead;lesstail=lesstail->next;}pHead=pHead->next;}lesstail->next=greaterhead->next;greatertail->next=NULL;free(lesshead);free(greaterhead);lesshead=greaterhead=NULL;return lesshead->next;}
};

第六题:回文结构(正序和倒序,顺序一样)

https://www.nowcoder.com/practice/d281619e4b3e4a60a2cc66ea32855bfa 

 

 

 第七题:相交链表

链表的相交和数学的直线相交不一样。因为链表只要有一个结点是一样的,那next也是一样的,之后都是相同的。

https://leetcode.cn/problems/intersection-of-two-linked-lists/description/

 

 

 

关键字:链表题目训练

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: