/**
* 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
Weekly Roundup 029 (Nov 27): 🔥Hot Topics🔥 in #workplace, #sharepoint, and #powerplatform
Hey fellow developers! It’s @jaloplo, here to give you the latest scoop on what’s been happening in the…
Programar sin Título Universitario
Para comenzar quiero dejar los siguientes puntos claros: El articulo está altamente influenciado por mi experiencia personal y…
Flutter University: Best Flutter Handbook Out There
Building the ultimate resource for Flutter developers. Wish I had this when I started learning Flutter 3 years…