Skip to content

Commit

Permalink
Create remove-list-node.py
Browse files Browse the repository at this point in the history
Created as a byproduct of misreading another question. performs well for the datasets I Have used
  • Loading branch information
gabedonnan authored Jan 17, 2023
1 parent 6538099 commit 300c124
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions remove-list-node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def removeNode(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
temp = head
prev = None
found = False
while not found:
if temp == None:
return head
if temp.val == n:
if prev:
prev.next = temp.next
else:
head = temp.next
prev = temp
temp = temp.next
return head

0 comments on commit 300c124

Please sign in to comment.