83. Remove Duplicates from Sorted List

来源:互联网 发布:苹果手机芒果tv没网络 编辑:程序博客网 时间:2024/06/04 00:28

又是去重,简单题,链表

/** * Definition for singly-linked list. * struct ListNode { *     int val; *     ListNode *next; *     ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:    ListNode* deleteDuplicates(ListNode* head) {        if(head == NULL) return head;        ListNode* t1 = head;        ListNode* t2 = head;        t2 = t2 -> next;        while(t2 != NULL){            if(t1 -> val == t2 -> val){                t2 = t2 -> next;                t1 -> next = t2;            }            else{                t1 = t1 -> next;                t2 = t2 -> next;            }        }        return head;    }};
0 0
原创粉丝点击