83. Remove Duplicates from Sorted List

来源:互联网 发布:世界历史地图软件 编辑:程序博客网 时间:2024/05/22 14:09

这道题很简单属于一遍ac题,放两个指针,一个在前,一个在后,只要他们俩值不同,就连起来,不管中间有什么。。。

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