/**
* 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
Teaching AI to Blog: My Journey into Agentic AI Development — Part 1
Recently, I embarked on my journey of learning agentic AI development, searching for an engaging project to kickstart…
IRF530 MOSFET: Pinout, Equivalent, Applications and Circuit Diagram
IRF530 is an N-channel MOSFET (100 V, 14 A) with low on-resistance (0.16 Ω). It’s commonly used in…
Achieving privacy compliance with your CI/CD: A guide for compliance teams
Now, you can extend your CI/CD systems to catch privacy and security issuing using Checks.