/**
* 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
Latest products and features at DigitalOcean: July 2022
In July, the team at DigitalOcean has been hard at work on key product enhancements for your favorite…
Write SQL Queries With Confidence (TypeScript + Postgres)
TL;DR- Check out https://safeql.dev A Problem Usually, we tend to operate against our database using ORMs such as…
Weekly web development resources #124
Sponsored Indie Worldwide The friendliest online community of bootstrapped startup founders. Get 1-1 introductions every week to other…