File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ ![ ] ( https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4uanNkZWxpdnIubmV0L2doL2Nob2NvbGF0ZTE5OTkvY2RuL2ltZy8yMDIwMDgyODE0NTUyMS5qcGc?x-oss-process=image/format,png )
2+ > 仰望星空的人,不应该被嘲笑
3+
4+ ## 题目描述
5+ 删除链表中等于给定值 val 的所有节点。
6+
7+ 示例:
8+
9+ ``` javascript
10+ 输入: 1 - > 2 - > 6 - > 3 - > 4 - > 5 - > 6 , val = 6
11+ 输出: 1 - > 2 - > 3 - > 4 - > 5
12+ ```
13+
14+ ## 解题思路
15+ 创建一个新链表,遇到相同值的情况,将当前节点的next指向下一个节点的next,否则继续遍历。
16+
17+ ``` javascript
18+ var removeElements = function (head , val ) {
19+ let dummyHead = new ListNode (); // 哑结点
20+ dummyHead .next = head;
21+ let p = dummyHead;
22+ while (p .next ){
23+ if (p .next .val === val){
24+ p .next = p .next .next ;
25+ }else {
26+ p = p .next ;
27+ }
28+ }
29+ return dummyHead .next ;
30+ };
31+ ```
32+
33+
34+
35+
36+
37+
38+ ## 最后
39+ 文章产出不易,还望各位小伙伴们支持一波!
40+
41+ 往期精选:
42+
43+ <a href =" https://github.com/Chocolate1999/Front-end-learning-to-organize-notes " >小狮子前端の笔记仓库</a >
44+
45+ <a href =" https://github.com/Chocolate1999/leetcode-javascript " >leetcode-javascript:LeetCode 力扣的 JavaScript 解题仓库,前端刷题路线(思维导图)</a >
46+
47+ 小伙伴们可以在Issues中提交自己的解题代码,🤝 欢迎Contributing,可打卡刷题,Give a ⭐️ if this project helped you!
48+
49+
50+ <a href =" https://yangchaoyi.vip/ " >访问超逸の博客</a >,方便小伙伴阅读玩耍~
51+
52+ ![ ] ( https://img-blog.csdnimg.cn/2020090211491121.png#pic_center )
53+
54+ ``` javascript
55+ 学如逆水行舟,不进则退
56+ ```
57+
58+
You can’t perform that action at this time.
0 commit comments