/**
* 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
A beginners guide to developer stock options
Are you in the same position as me? Do you hear about developer stock options, but have no…
Meet Rose Niousha, GDSC Waseda Founder & WTM Ambassador
Posted by Takuo Suzuki, Developer Relations Program Manager, Japan Rose Niousha wanted to create a community where students…
API Rate Limiting Cheat Sheet
Jump to a section: Gateway-level rate limiting Token bucket algorithm Leaky bucket algorithm Sliding window algorithm Distributed rate…