Skip to content

Commit 2e3432b

Browse files
committed
Add solution #203
1 parent 1ee3e62 commit 2e3432b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
141|[Linked List Cycle](./0141-linked-list-cycle.js)|Easy|
4747
151|[Reverse Words in a String](./0151-reverse-words-in-a-string.js)|Medium|
4848
152|[Maximum Product Subarray](./0152-maximum-product-subarray.js)|Medium|
49+
203|[Remove Linked List Elements](./0203-remove-linked-list-elements.js)|Easy|
4950
217|[Contains Duplicate](./0217-contains-duplicate.js)|Easy|
5051
219|[Contains Duplicate II](./0219-contains-duplicate-ii.js)|Easy|
5152
226|[Invert Binary Tree](./0226-invert-binary-tree.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 203. Remove Linked List Elements
3+
* https://leetcode.com/problems/remove-linked-list-elements/
4+
* Difficulty: Easy
5+
*
6+
* Given the head of a linked list and an integer val, remove all the
7+
* nodes of the linked list that has Node.val == val, and return the
8+
* new head.
9+
*/
10+
11+
/**
12+
* Definition for singly-linked list.
13+
* function ListNode(val, next) {
14+
* this.val = (val===undefined ? 0 : val)
15+
* this.next = (next===undefined ? null : next)
16+
* }
17+
*/
18+
/**
19+
* @param {ListNode} head
20+
* @param {number} val
21+
* @return {ListNode}
22+
*/
23+
var removeElements = function(head, val) {
24+
if (!head) return null;
25+
head.next = removeElements(head.next, val);
26+
return head.val === val ? head.next : head;
27+
};

0 commit comments

Comments
 (0)