/**
* 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 sleek solidity cheatsheet
part 1 of a 5 part series on essentials for solidity devs solidity_cheatsheet.sol cryptography_cheatsheet.sol assembly_cheatsheet.sol designPatterns_cheatsheet.sol security_cheatsheet.sol It…
Day 40: Implementing Advanced Role-Based Access Control (RBAC) with OPA Gatekeeper
Introduction Understanding Role-Based Access Control (RBAC) has always been a goal of mine, especially in the context of…
💬 Integrating Twilio into your project: Part 3 – Handling Webhooks and Sending Messages with Laravel and Express
In this part, we’ll: Create a simple service to send WhatsApp messages. Handle incoming WhatsApp messages by replying…