Skip to content

Commit 2ad1b6f

Browse files
solves remove a linked list element
1 parent 90317bd commit 2ad1b6f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/NumberOf1Bit.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/number_of_1_bits.py) |
5858
| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HouseRobber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/house_robber.py) |
5959
| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/HappyNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/happy_number.py) |
60-
| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) |
60+
| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/RemoveLinkedListElements.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/remove_linked_list_elements.py) |
6161
| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/CountPrimes.java) |
6262
| 205 | [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/IsomorphicStrings.java) |
6363
| 206 | [Reverse Linked Lists](https://leetcode.com/problems/reverse-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ReverseLinkedList.java) |

python/remove_linked_list_elements.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Union
2+
3+
4+
# Definition for singly-linked list.
5+
class ListNode:
6+
def __init__(self, val=0, next=None):
7+
self.val = val
8+
self.next = next
9+
10+
11+
class Solution:
12+
def removeElements(self, head: ListNode, val: int) -> Union[None, ListNode]:
13+
current = ListNode(val=0, next=head)
14+
start = current
15+
while current is not None and current.next is not None:
16+
if current.next.val == val:
17+
current.next = current.next.next
18+
else:
19+
current = current.next
20+
return start.next

0 commit comments

Comments
 (0)