Skip to content

Commit 9ff5edd

Browse files
committed
Adding Simple Solution for Problem - 237 - Delete Node Linked List
1 parent 6c877da commit 9ff5edd

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 237
6+
## Problem Name: Delete Node in a Linked List
7+
##===================================
8+
#
9+
#Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
10+
#
11+
#Given linked list -- head = [4,5,1,9], which looks like following:
12+
#
13+
# 4 >> 5 >> 1 >> 9
14+
#
15+
#Example 1:
16+
#
17+
#Input: head = [4,5,1,9], node = 5
18+
#Output: [4,1,9]
19+
#Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.
20+
#
21+
#Example 2:
22+
#
23+
#Input: head = [4,5,1,9], node = 1
24+
#Output: [4,5,9]
25+
#Explanation: You are given the third node with value 1, the linked list should become 4 -> 5 -> 9 after calling your function.
26+
class Solution:
27+
def deleteNode(self, node):
28+
node.val = node.next.val #Value will be node.next's value
29+
node.next = node.next.next #We'll point the node to node.next.next
30+
#Example:
31+
#head = [4, 5, 1, 9]
32+
#node = 5
33+
#node.val = node.next.val = 1
34+
#node.next = node.next.next ---- this will point to node.next.next
35+
#head = [4, 1, 9]

0 commit comments

Comments
 (0)