/**
* 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
Arrow function in Javascript
Arrow functions are one of the handy features introduced in ES6. Using arrow functions correctly can make your…
Bicep Extension Finally Arrives in Visual Studio! Here’s What You Need to Know
Bicep, the open source project used by Visual Studio Code to extend its capabilities, has finally arrived in…
VueJS part 14: Scoped slots and conditional slot rendering
Introduction Recently, I started learning VueJS, and this article is part of the series of my notes while…