<h3><a title="题目描述" href="https://leetcode-cn.com/problems/remove-linked-list-elements/">题目描述</a></h3>
![file](https://i.loli.net/2019/11/11/dIzQOMt6AuvcD4H.png)
<h4>解法</h4>
<pre class="EnlighterJSRAW" data-enlighter-language="null"># Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def removeElements(self, head: ListNode, val: int) -> ListNode:
l = ListNode(-1)
l.next = head
pre,cur = l,head
while(cur):
if(cur.val == val):
pre.next = cur.next
cur = cur.next
else:
pre = cur
cur = cur.next
return l.next</pre>
#### Note:
- 唉 我真是太菜了...数据结构基本操作这么个题能写20分钟啊啊啊..还不是bug-free写出来的
- **处理链表问题时,是不是要考虑增设虚节点,虚节点.next = head**会比较方便呢?
- 上面这段代码一定写的很丑 有优化改进的空间...~~但是我懒~~
> `class Typename():`
Type = Typename(*) //*即为初值 这个东西好像忘记了..我怎么这么菜啊!
- 啥时候刷简单题无压力bug-free了(会有那天嘛?) 就开始整中等题
Leetcode203 移除链表元素