/**
* 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
Rspack with Module federation V2 is the future
The module federation team cared deeply about the DevX in their latest release. The purpose of this blog…
A Beginner’s Guide to Building LLM-Powered Applications with LangChain!
If you’re a developer or simply someone passionate about technology, you’ve likely encountered AI tools such as ChatGPT.…
How to Store Critical Secrets for 100+ Years
The “Root of Trust” Problem Every sophisticated security system eventually collapses into a single point of failure: one…