/**
* 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
Soul | A SQLite RESTful server
Hi Folks, For the last few weeks I’ve been working on Soul. As the title says, it’s a…
Let’s clarify some misconceptions around android development these days
Photo by Agence Olloweb on Unsplash Forget the Formalities ! There’s no introduction for this blogpost 😅 (or maybe I…
Top 5 Developer Soft Skills
as a developer you need to have some skills, but not all skills have to be technical skills,…