每天进步一点点
恭喜龙队,小胖,王
题目描述
- 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例 1: 输入: 1->1->2 输出: 1->2 示例 2: 输入: 1->1->2->3->3 输出: 1->2->3
思路分析
有序 重复
function ListNode(val, next = null) {
this.val = val
this.next = next
}
/**
*
* @param {ListNode} head
* @return {ListNode}
*/
function deleteDuplicates(head){
let temp = head
while(temp != null && temp.next != null){
if(temp.val === temp.next.val){
temp.next = temp.next.next
}else{
temp = temp.next
}
}
return head
}
baybay!!