Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Leetcode Delete Node in a Linked List problem solution

YASH PAL, 31 July 202420 January 2026

In this Leetcode Delete Node in a Linked List problem solution Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead, you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list.

Leetcode Delete Node in a Linked List problem solution

Leetcode Delete Node in a Linked List problem solution in Python.

def deleteNode(self, node: ListNode, n: int) -> None:
    while node.val != n:
        node = node.next
    node.val = node.next.val
    node.next = node.next.next
    return

Delete Node in a Linked List problem solution in Java.

class Solution {
    public void deleteNode(ListNode node) {
        while(node.next.next!=null)
        {
            node.val=node.next.val;
            node=node.next;
        }
        node.val=node.next.val;
        node.next=null;
    }

Problem solution in C++.

class Solution {
public:
void deleteNode(ListNode* node) {
*node = *(node->next);
}
};

Problem solution in C.

void deleteNode(struct ListNode* node) {

struct ListNode *temp=node;
struct ListNode *temp1=NULL;

while(temp->next != NULL)
{
    temp->val=temp->next->val;
    temp1=temp;
    temp=temp->next;
}
temp1->next=NULL;
free(temp);
}

coding problems solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes