?LeetCode刷題實(shí)戰(zhàn)203:移除鏈表元素
題意
示例
輸入: 1->2->6->3->4->5->6, val = 6
輸出: 1->2->3->4->5
解題
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
ListNode* x = new ListNode(-1);
x->next = head;
ListNode* i = x;
while(i->next)
{
if(i->next->val == val)
{
i->next = i->next->next;
}
else
{
i = i->next;
}
}
return x->next;
}
};
LeetCode1-200題匯總,希望對(duì)你有點(diǎn)幫助!
LeetCode刷題實(shí)戰(zhàn)201:數(shù)字范圍按位與
評(píng)論
圖片
表情
