Remove Linked List Elements

原创 2015年07月07日 10:37:28
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* removeElements(ListNode* head, int val) {
        ListNode *dumbHead = new ListNode(0);
        dumbHead->next = head;

        ListNode *pForward, *pBackward;
        pBackward = dumbHead;
        pForward = pBackward->next;
        for(; pForward != NULL; ) {
            if(pForward->val == val) {
                pBackward->next = pForward->next;
                pForward = pBackward->next;
            }else {
                pBackward = pForward;
                pForward = pForward->next;
            }
        }
        return dumbHead->next;
    }
};

数据结构之Remove Linked List Elements 以及二叉树对称Symmetric Tree

今天继续来闲话几句数据结构之单链表,题目的意思是删除链表中的特定元素,想来想去用C/C++ 来coding,才能更深刻的理解数据结构,故而以后在关于数据结构方面,我尽量用c/c++ 来coding。看...

[LeetCode] Remove Linked List Elements

Remove all elements from a linked list of integers that have value val. Example Given: 1 –> 2 –> 6...

Leetcode 203. Remove Linked List Elements

Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –...

Leetcode_203_Remove Linked List Elements

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/45868027 Remove all el...

203. Remove Linked List Elements

描述: Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –...

leetcode 203. Remove Linked List Elements

我觉得在使用链表的时候一般有两种思路:一种是链表的内容可以修改,在原链表上进行处理,后续的操作不需要使用原链表的内容的时候这种思路可以节约空间和时间;另外一种是当我们不能更改链表的内容,后续需要用到的...

Remove Linked List Elements - LeeCode 203

题目描述: Remove all elements from a linked list of integers that have value val. Example Given: 1 ...
  • bu_min
  • bu_min
  • 2015年05月17日 11:48
  • 221

Remove Linked List Elements

Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -...

LeetCode Remove Linked List Elements

题目: Remove all elements from a linked list of integers that have value val. Example Given: ...

<LeetCode OJ> 203. Remove Linked List Elements

203. Remove Linked List Elements My Submissions Question Total Accepted: 45239 Total Submissions...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Remove Linked List Elements
举报原因:
原因补充:

(最多只允许输入30个字)