leetcode+ 有序链表删除相同元素

点击打开链接
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* root = head;
        while (head != NULL) {
            /*下一节点存在,且当前节点和下一节点的值重复*/
            while (head->next != NULL && head->val == head->next->val) {
                head->next = head->next->next;
            }
            head = head->next;
        }
        return root;
    }
};

猜你喜欢

转载自blog.csdn.net/u013554860/article/details/80834060
今日推荐