/**
* 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
Beyond English: How Gemma open models are bridging the language gap
AI Singapore and INSAIT teams have leveraged Gemma, a family of open-source language models, to create LLMs tailored…
Getting started with docker
What are containers? Containers are a way of packaging applications together with all required dependencies and configuration, making…
SQL Commands that every Developer should know
Here are some SQL commands that every developer should know: SELECT INSERT DROP TABLE UPDATE DELETE CREATE TABLE…