leetcode-83. 删除排序链表中的重复元素

题目

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

代码

/*
 * @lc app=leetcode.cn id=83 lang=java
 *
 * [83] 删除排序链表中的重复元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode pNode = null;
        ListNode current = head;
        while (current != null) {
            int v = current.val;
            if (pNode != null) {
                int pv = pNode.val;
                if (v == pv) {
                    pNode.next = current.next;
                    current = current.next;

                    continue;
                }
            }

            pNode = current;
            current = current.next;
        }

        return head;
    }
}
// @lc code=end


你可能感兴趣的:(leetcode-83. 删除排序链表中的重复元素)