203. Remove Linked List Elements
2016-06-05 19:28
225 查看
题目:https://leetcode.com/problems/remove-linked-list-elements/
代码:
代码:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode removeElements(ListNode head, int val) { if(head == null) return null; while(head!=null&&head.val == val) { head = head.next; } ListNode temp = head; while(temp!=null&&temp.next!=null) { if(temp.next.val==val) { temp.next = temp.next.next; } else temp = temp.next; } return head; } } 2ms ========================================================
相关文章推荐
- DHU--2083简易版之最短距离
- 345. Reverse Vowels of a String
- Adapter适配器与具体应用
- 回滚点
- OC 类簇与复合
- Some settings of PostgreSQL
- 浅谈Javascript中的void操作符
- 给学PHP、工作中在用PHP的朋友们推荐几本书 浏览:3734次 出处信息 原文:http://www.xingmo.cn/html/20090401/81.html PHP与
- c++第七次实验——特殊的三位数
- 21. Merge Two Sorted Lists
- 121. Best Time to Buy and Sell Stock
- BZOJ3612 [Heoi2014]平衡
- Android的Handler,Looper源码剖析
- 《软件工程》第十四周学习进度
- “进度条”博客——第十四周
- 控制音乐播放器的退出再次播放相同音乐的功能实现
- 141. Linked List Cycle
- DNS原理及其解析过程【精彩剖析】
- [PHP] MVC思想----错误处理类
- 文章标题