/**
* 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
840. Magic Squares In Grid
840. Magic Squares In Grid Medium Topics: Array, Hash Table, Math, Matrix A 3 x 3 magic square…
Building AI-Powered Apps with Vercel AI SDK and React
Building AI-Powered Applications with Vercel AI SDK and React Server Components Introduction In the rapidly evolving landscape of…
TUGAS DPK-TJKT SEJARAH PERKEMBANGAN TEKNOLOGI TEMA 1-9
NAMA: TSANIA KHILYATIN NADA KELAS: X TJKT 2 NO ABSEN: 32 *#Tema 1 : Jenis teknologi perkembangan prosesor…