链表题目训练

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/

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值