/**
* 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
Built a Sudoku Game Using Amazon Q CLI on WSL Ubuntu – Try It Out!
I’m thrilled to share my experience building a browser-based Sudoku puzzle game using the new Amazon Q CLI…
How to make your AI Agent 111x cheaper and 2.5x faster at data aggregation
Google recently released an incredibly fast new model — Gemini 3.5 Flash. As someone building infrastructure for autonomous…
500+ hours of uninterrupted live streaming on Twitch and YouTube with Serverspace
Or in another way, the story of how a data engineer from Germany created a project in the…