Remove Duplicates from Sorted List

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
LeetCode Problem - 83
/**
* Definition for singly-linked list.
* public class ListNode {
* int val; // value of the node
* ListNode next; // reference to the next node in the list
* ListNode() {} // default constructor
* ListNode(int val) { this.val = val; } // constructor with value only
* ListNode(int val, ListNode next) { this.val = val; this.next = next; } // constructor with value and next node
* }
*/
class Solution {
// Method to remove duplicates from a sorted linked list
public ListNode deleteDuplicates(ListNode head) {
// If the list is empty, return null
if (head == null) return null;
// Pointer to the current node being checked
ListNode current = head;
// Traverse the linked list
while (current != null && current.next != null) {
// If the current node's value is the same as the next node's value
if (current.val == current.next.val) {
// Skip the next node by changing the next pointer
current.next = current.next.next;
} else {
// Move to the next node if no duplicate is found
current = current.next;
}
}
// Return the head of the modified list (with duplicates removed)
return head;
}
}




