/**
* 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
Host LLMs from Your Laptop Using LM Studio and Pinggy
Introduction In the era of generative AI, software developers and AI enthusiasts are continuously seeking efficient ways to…
Do Night Owls Code Better?
Are you a night owl coder? Share your experiences with late-night programming. What advantages and challenges do you…
What is Stablecoin Settlement
Stablecoin settlement is what happens when a business receives payment in a dollar-pegged digital currency instead of routing…