[Lintcode] #452 删除链表中的元素
来源:互联网 发布:linux mv 隐藏文件 编辑:程序博客网 时间:2024/06/05 18:38
删除链表中等于给定值val
的所有节点。
样例
给出链表 1->2->3->3->4->5->3
, 和 val = 3
, 你需要返回删除3之后的链表:1->2->4->5
。
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { /* * @param head: a ListNode * @param val: An integer * @return: a ListNode */ public ListNode removeElements(ListNode head, int val) { ListNode newHead = new ListNode(0);newHead.next = head;ListNode cur = newHead;while (cur.next != null) {if (cur.next.val == val)cur.next = cur.next.next;elsecur = cur.next;}return newHead.next; }}
阅读全文
0 0
- LintCode 452 删除链表中的元素
- lintcode 452 删除链表中的元素
- LintCode:删除链表中的元素452
- [Lintcode] #452 删除链表中的元素
- LintCode-删除链表中的元素
- LintCode之删除链表中的元素
- 【Lintcode】删除链表中的元素
- LintCode【入门】删除链表中的元素
- lintcode(E) 删除链表中的元素
- lintcode-入门-删除链表中的元素
- LintCode 删除链表中的元素
- LintCode 删除链表中的元素
- 删除链表中的元素-LintCode
- Lintcode 452.删除链表中的元素
- LintCode : 删除链表中的重复元素
- [LintCode]452.删除链表中的元素
- LintCode 删除链表中的元素
- [lintcode]-链表 删除链表中的元素
- 翻转(reverse)字符串(string)的所有方法
- 外部数据库驱动程序(1)中的意外错误
- C#串口调试助手
- Oracle 简单sql
- 小知识点
- [Lintcode] #452 删除链表中的元素
- Codeforces Round #443 (Div. 2) A. Borya's Diagnosis
- pgsql9.1 基于wal的完全恢复
- java趣味算法(一)——约瑟夫问题
- 2017.10.26模拟赛day1
- leetcode解题方案--023--Merge k Sorted Lists
- [论文笔记]Predicting Deeper into the Future of Semantic Segmentation
- Python print() 函数
- CSS中的塌陷问题总结