Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such this each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
https://leetcode.com/problems/remove-duplicates-from-sorted-list/
Remove the duplicate nodes from the list, the linked list is ordered, and it is good to write a variable down to the previous node.
1 /**2 * Definition for singly-linked list.3 * Function ListNode (val) {4 * This.val = val;5 * this.next = null;6 * }7 */8 /**9 * @param {listnode} headTen * @return {ListNode} One */ A varDeleteduplicates =function(head) { - varh =NewListNode ( -1), tail = h, previous =NULL; - while(head) { the if(Head.val!==Previous) { -Tail.next =head; -Tail =Tail.next; - } +Previous =Head.val; -Head =Head.next; + } ATail.next =NULL; at returnH.next; -};
[Leetcode] [JavaScript] Remove Duplicates from Sorted List