LeetCode 203
2016-04-24 23:11
190 查看
Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.
Example
Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5
Remove all elements from a linked list of integers that have value val.
Example
Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5
/** * 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) { ListNode fakehead = new ListNode(-1); fakehead.next = head; ListNode n = fakehead; if(head == null){ return head; } while(n.next != null){ if(n.next.val == val){ n.next = n.next.next; }else{ n = n.next; } } return fakehead.next; } }
相关文章推荐
- c++ primer(第五版)学习笔记及习题答案代码版(第二章)
- 20145310《Java程序设计》第3次实验报告
- API 双方认证探讨
- PHP——图片上传
- LigerUI中通过加载服务端数据进行表格的分页显示
- sed命令解析
- 程序员怎么在短时间内从菜鸟到高级架构师
- LeetCode 202
- QT基础(三)----QPainter画图功能 & 画图小项目
- 数据库范式
- Win7下尝试编译Fast RCNN---- 一次失败的经历
- spark 性能优化
- Linux系统时间和硬件时间设置
- Swift爬坑记-CAKeyframeAnimation略解
- Android系统内核引导流程梳理
- LeetCode 136
- iOS自定义控件的封装细节
- Android成长之路(3)——Activity的生命周期(1)
- 20145335郝昊《java程序设计》第8周学习总结
- 20145129实验报告(三)