/**
* 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;
}
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
Hey there! Thank you for sharing your solution. While the code snippet looks nice, I think it would be more helpful for the community if you could explain the thinking behind the code. This would not only benefit other members in understanding the solution but also promote a healthy learning environment for everyone. So, next time, could you please add some explanation alongside the code? Thank you for your cooperation!