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) { if (head == null) { return null; } ListNode listNode = new ListNode(0); listNode.next = head; head = listNode; while (head.next != null) { if (head.next.val == val) { head.next = head.next.next; } else { head = head.next; } } return listNode.next; } }
相关推荐
leetcode 2 sum c LeetCode 帮助文档 帮助文档存放在Help文件夹下。 文件名 文件描述 ...complexitypython.txt Python的一些常规操作的...Elements no 206 Easy Reverse Linked List 234 Easy Palindrome Linked List
Elements 力扣 206 反转链表 | Reverse Linked List 队列 Queue 力扣 933 最近的请求次数 | Number of Recent Calls 力扣 225 用队列实现栈 | Implement Stack Using Queue 力扣 622 设计循环队列 | Design ...
关于algorithm and data structure的一个linked list的C++的code
* [Linked List](https://github.com/kamyu104/LeetCode#linked-list) * [Stack](https://github.com/kamyu104/LeetCode#stack) * [Queue](https://github.com/kamyu104/LeetCode#queue) * [Heap]...
creat() linked list;print(),output linked list;insert(),input index, before data(index)insert new data,if index >c,insert into the end. delede(),delete data(index),0;change(),input index_i and index_...
用linked list来写priority queue
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→...
a very comprehensive tutorial on circular linked list
We introduce a method to dynamically construct highly concurrent linked lists on modern graphics processors. Once constructed, these data structures can be used to implement a host of algorithms ...
该代码的主要功能是根据双向链表中的数据大小排序,排序方式是选择法和冒泡法两种,其中选择法是用交换指针来实现的。
THIS IS DOUBLY LINKED LIST SOURCE
在https://github.com/gramoli/synchrobench上进行修改更适于Synchrobench’s Lazy Linked-List进行内存回收,解决了内存泄漏问题
this is a template design for doubly linked list. it is just a reference for one who want to study template programming.
C doubly linked list
java 内置迭代器的linked list例题
Linked List Template连接列表模板
infix to postfix using linked list
在linux环境下已测试,放心使用,这个是根据stanford cs library的linked list文章里的代码敲出来的
In the module entry point, create a linked list containing five struct birthday elements. Traverse the linked list and output its contents to the kernel log buffer. Invoke the dmesg command to ensure ...