JAVA CLEAR EXPLANATION OF QUESTION AND LOGIC BEHIND THE ANSWER!
ok lets do this!!\ni see a lot of people unabe to explain the question and the solution!\nlet me first explain the question!!\nquestion says to remove the dupli
ok lets do this!!\ni see a lot of people unabe to explain the question and the solution!\nlet me first explain the question!!\nquestion says to remove the duplicates from an sorted linked list!\n(piece of advice-whenever you are given a sorted ds ,this is a hint that the question is easy....so dont think too much)\nanyways lets see some ex:\n1->2->2->3->3->4;\nwe are required to remove ALL THE DUPLICATES ;\nthus final list would be\n1->4\nand not\n1->2->3->4;\n\nso lets go into the solution!\nlike any other linked list problem lets take two pointer,\none fast and one slow!\nthe fast and slow both move one step at a time but fast is always ahead of slow as fast starts one node further than slow in the beginning!\nLOGIC AND INTUITION:\n"thus the function of our fast node is to search for duplicates and wait for slow to catch up before moving any further!\nin other words whenever fast detects a duplicate it would keep traversing till the last duplicate and then wait..\nthe slow pointer will remove(delete) all the duplicate in the way and finally come to  fast node!\nthis process continues till the fast encounters a null value indicating end of linkedl list"\n\nINITIALLY WE ALSO NEED A DUMMY NODE SO THAT FAST IS ONE STEP AHEAD OF SLOW!\n\n```\npublic class Solution {\npublic ListNode deleteDuplicates(ListNode head) {\n    ListNode dummy = new ListNode(0), fast = head, slow = dummy;\n    slow.next = fast;\n    while(fast != null) {\n    \twhile (fast.next != null && fast.val == fast.next.val) { // this loop basically takes fast to end of the current duplicates that we are tracking\n     \t\tfast = fast.next;   \n    \t}\n    \tif (slow.next != fast) { \n    \t\tslow.next = fast.next; //remove the duplicates.\n    \t\tfast = slow.next;     //fast moves to next unique value .\n    \t} else { //no duplicates...lets move towards right!!.\n    \t\tslow = slow.next;\n    \t\tfast = fast.next;\n    \t}\n    \t\n    }\n    return dummy.next;\n} }\n\n\nhope it helps!!
['Java']