Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d193a15

Browse files
authored
Create Remove_Linked_List_Elements.py
1 parent 43ef6ef commit d193a15

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎Remove_Linked_List_Elements.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# URL: https://leetcode.com/problems/remove-linked-list-elements/
2+
# This method handles all the edge cases - All values are same, starting node value is val etc.,
3+
4+
class Solution:
5+
def removeElements(self, head: Optional[ListNode], val: int) -> Optional[ListNode]:
6+
dummy = ListNode(-1)
7+
dummy.next = head
8+
9+
t_head = dummy
10+
while t_head.next:
11+
if t_head.next.val == val:
12+
t_head.next = t_head.next.next
13+
else:
14+
t_head = t_head.next
15+
16+
return dummy.next
17+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /