题解 | #牛群排列去重#
牛群排列去重
https://www.nowcoder.com/practice/8cabda340ac6461984ef9a1ad66915e4
/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return ListNode类
*/
function deleteDuplicates( head ) {
// write code here
let l1 = head
while(l1 && l1.next) {
if(l1.val === l1.next.val) {
l1.next = l1.next.next;
} else {
l1 = l1.next;
}
}
return head
}
module.exports = {
deleteDuplicates : deleteDuplicates
};
直接声明一个链表 然后移动就行了

查看14道真题和解析