🔥🔥 Explicación y Resolución Del Ejercicio En Español Java | Python | PHP | C++ | JavaScript  🔥🔥
Lectura\n\nEliminar duplicados de la lista ordenada ll (Java, Python, PHP, C++, Javascript)\n\nDado una lista enlazada ordenada, elimine todos los nodos que ten
# Lectura\n\n*Eliminar duplicados de la lista ordenada ll (Java, Python, PHP, C++, Javascript)*\n\nDado una lista enlazada ordenada, elimine todos los nodos que tengan n\xFAmeros duplicados, dejando solo n\xFAmeros distintos de la lista original. \n\n![remove-duplicates-from-sorted-list-II-leetcode-espanol-1.jpg](https://assets.leetcode.com/users/images/60f88053-e0b7-4502-a9b0-d82f511e8f53_1695765508.0070865.jpeg)\n\nPara eliminar los duplicados de una lista enlazada ordenada, utilizaremos un algoritmo espec\xEDfico que nos permitir\xE1 obtener una nueva lista con valores \xFAnicos. \n\nEl algoritmo consiste en recorrer la lista enlazada y comparar cada valor con el siguiente. Si son iguales, avanzamos el puntero hasta el \xFAltimo nodo que tenga valores repetidos y conectamos el puntero conector con la siguiente posici\xF3n del puntero head. Si son distintos, avanzamos el puntero conector a su siguiente posici\xF3n. \n\n# Explicaci\xF3n del ejercicio Paso por paso\n\nhttps://youtu.be/-StgarM-hEw\n\nSi te gust\xF3 el contenido \xA1visita mi canal de youtube!: \n\u2705https://www.youtube.com/@hermescoder\n\nSi deseas profundizar m\xE1s en este tema \xA1visita mi blog!: \n\u2705https://hermescoder.com/remove-duplicates-from-sorted-list-II-leetcode-espanol.html\n\n# C\xF3digo \n\n```Java []\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public static ListNode deleteDuplicates(ListNode head) {\n        //paso #1\n        ListNode home = new ListNode(0);\n        home.next = head;\n\n        //paso #2\n        ListNode conector = home;\n\n        //paso #3\n        while (head != null && head.next != null ) {\n            //paso #4\n            if (head.val != head.next.val) {\n                //head 4.1.1\n                conector = conector.next;\n            } else {\n                //paso 4.1.2\n                while (head.next != null && head.val == head.next.val) head.next = head.next.next;\n                conector.next = head.next;\n            }\n\n            //paso 4.2\n            head = head.next;\n        }\n\n        //paso 5\n        return home.next;\n    }\n\n}\n```\n```Python []\n# Definition for singly-linked list.\n# class ListNode(object):\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution(object):\n    def deleteDuplicates(self, head):\n        home  = ListNode(0)\n        home.next = head\n        conector = home\n\n        while head and head.next:\n            if head.next.val == head.val:\n                while head.next and head.val == head.next.val:\n                    head= head.next\n                conector.next = head.next\n            else:\n                conector = conector.next\n            head= head.next\n\n        return home.next\n```\n```PHP []\n/**\n * Definition for a singly-linked list.\n * class ListNode {\n *     public $val = 0;\n *     public $next = null;\n *     function __construct($val = 0, $next = null) {\n *         $this->val = $val;\n *         $this->next = $next;\n *     }\n * }\n */\nclass Solution {\n\n    /**\n     * @param ListNode $head\n     * @return ListNode\n     */\n    function deleteDuplicates($head) {\n\n        //paso #1\n        $home= new ListNode(null);\n        $home->next=$head;\n\n        //paso #2\n        $conector=$home;\n\n\n        //paso #3\n        while($head ->next !=null){\n\n            //paso #4\n            if($head->val != $head->next->val){\n                //paso 4.1.1\n                $conector = $conector->next;\n            }\n\n            else {\n                //paso 4.1.2\n                while($head->next != null &&  $head->val == $head->next->val)\n                    $head=$head->next;\n                $conector->next= $head->next;\n            }\n\n            //paso 4.2\n            $head=$head->next;\n        }\n\n        //paso 5\n        return $home->next;\n    }\n}\n```\n```C++ []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n       if (!head || !head->next) return head;\n\n        ListNode* home = new ListNode(0);\n        home->next = head;\n\n        ListNode* conector = home;\n\n        while (head && head->next != nullptr) {\n            if (head->val != head->next->val) {\n                conector = conector->next;\n            } else {\n                while (head->next != nullptr && head->val == head->next->val) {\n                head = head->next;\n                }\n                conector->next = head->next;\n            }\n\n        head = head->next;\n        }\n\n        return home->next;\n    }\n};\n```\n```JavaScript []\n/**\n * Definition for singly-linked list.\n * function ListNode(val, next) {\n *     this.val = (val===undefined ? 0 : val)\n *     this.next = (next===undefined ? null : next)\n * }\n */\n/**\n * @param {ListNode} head\n * @return {ListNode}\n */\nvar deleteDuplicates = function(head) {\n    if (!head || !head.next) return head;\n\n    const home = new ListNode(null);\n    home.next = head;\n\n    let conector = home;\n\n    while (head && head.next) {\n      if (head.val !== head.next.val) {\n        conector = conector.next;\n      } else {\n        while (head.next && head.val === head.next.val) {\n          head = head.next;\n        }\n        conector.next = head.next;\n      }\n\n      head = head.next;\n    }\n\n    return home.next;\n\n};\n```\n\n![upvote.png](https://assets.leetcode.com/users/images/35df971c-9658-4be5-abfd-f214402aa92a_1695916553.616385.png)\n\n\n\n\n
['Linked List', 'PHP', 'Python', 'C++', 'Java', 'JavaScript']