/**
* @author xienl
* @description
* @date 2022/7/4
*/
public class Solution {
public static void main(String[] args) {
}
public ListNode deleteDuplicates (ListNode head) {
// write code here
if (head == null){
return null;
}
ListNode dummy = new ListNode(-1);
dummy.next = head;
ListNode cur = dummy;
while (cur != null){
while (cur.next != null && cur.val == cur.next.val){
cur.next = cur.next.next;
}
cur = cur.next;
}
return dummy;
}
}
class ListNode {
int val;
ListNode next = null;
public ListNode(int val) {
this.val = val;
}
}
牛客网:NC25 删除有序链表中重复的元素-I
最新推荐文章于 2024-07-12 21:20:02 发布