LeetCode 删除排序链表中的重复元素
程序员文章站
2022-07-08 08:54:15
...
LeetCode 删除排序链表中的重复元素
题目
代码
/**
* Definition for singly-linked list.
* public class ListNode {
* public int val;
* public ListNode next;
* public ListNode(int x) { val = x; }
* }
*/
public class Solution
{
public ListNode DeleteDuplicates(ListNode head)
{
ListNode temp = head;
while (temp != null)
{
while (temp.next != null && temp.val == temp.next.val)
temp.next = temp.next.next;
temp = temp.next;
}
return head;
}
}