/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode temp = head;
if(temp==null){
return temp;
}else if(temp.next==null){
return temp;
}
ListNode prev = temp;
temp = temp.next;
while(temp!=null){
if(temp.val == prev.val){
prev.next = temp.next;
temp = temp.next;
}else{
prev = temp;
temp = temp.next;
}
}
return head;
}
}
Related Posts
OpenAI Unleashes GPT-4o!
The future of AI just got a whole lot more exciting (and maybe a little bit scary)! Yesterday,…
Creating Custom API Endpoints in Salesforce with Apex
Part One: SOAP-based APIs Simple Object Access Protocol (SOAP) is a messaging protocol based on requests and responses…
Deploying Your First Application on Kubernetes: Step-by-Step Tutorial
In this tutorial, we’ll delve into the intricacies of Kubernetes Development and guide you through each step of…