/**
* 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
Linux in Action – File Structure Hierarchy and Its Role in Modern Business
Introduction Linux is a powerful and versatile operating system that has become the backbone of many businesses and…
A verdade sobre os bootcamps de programação
Os grandes criadores de bootcamps de programação sabem que as pessoas tendem a desejar mais um curso quando…
Gin vs Spring Boot: A Detailed Comparison
When choosing a backend framework, Gin (Go) and Spring Boot (Java) are often compared for their performance, scalability,…