LeetCode83. 删除排序链表中的重复元素

题目来源:

https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/description/

题目描述:

由于该题比较简单,就直接写代码了。代码如下: 

class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if (head != null) {
            ListNode cur = head;
            while (cur.next != null) {
                if (cur.val == cur.next.val) {
                    cur.next = cur.next.next;
                }
                else {
                    cur = cur.next;
                }
            }
        }
        return head;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_39241239/article/details/84205283