Difficult:Easy
題目
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.
翻譯
給定排序鍊錶的頭部,刪除所有重複項,使每個元素只出現一次。返回排序好的鍊錶。
範例
Example 1:
1 | Input: head = [1,1,2] |
Example 2:
1 | Input: head = [1,1,2,3,3] |
解題思路
1.設當前及存放開頭的變數
2.當遇到相同值時,依序往前比較
Solution
1 | var deleteDuplicates = function (head) { |