Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • 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
Programming101
Programming101

Learn everything about programming

Leetcode Delete Node in a Linked List problem solution

YASH PAL, 31 July 2024

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

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

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

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
©2025 Programming101 | WordPress Theme by SuperbThemes