Categories: Thủ Thuật Mới

Mẹo Remove Duplicates from Sorted list II Java 2022

Mục lục bài viết

Kinh Nghiệm về Remove Duplicates from Sorted list II Java 2022

Update: 2021-12-09 07:26:06,Bạn Cần biết về Remove Duplicates from Sorted list II Java. Bạn trọn vẹn có thể lại Thảo luận ở cuối bài để Admin đc lý giải rõ ràng hơn.


leetcode/problems/remove-duplicates-from-sorted-list-ii/

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.

Example 1:

Input: 1->2->3->3->4->4->5
Output: 1->2->5

Example 2:

Input: 1->1->1->2->3
Output: 2->3

Code:

/**
* 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) !head ->next) return head;
ListNode *dummy = new ListNode(-1), *pre = dummy;
dummy -> next = head;
while(pre -> next)
ListNode *cur = pre -> next;
while(cur -> next && cur -> val == cur -> next -> val)
cur = cur -> next;
if(cur != pre -> next) pre -> next = cur -> next;
else pre = pre -> next;

return dummy ->next;

;

  It is possible to repeat what you want to be deleted so to Dummy.

FHFHFH

đoạn Clip hướng dẫn Share Link Down Remove Duplicates from Sorted list II Java ?

– Một số từ khóa tìm kiếm nhiều : ” Review Remove Duplicates from Sorted list II Java tiên tiến và phát triển nhất , Share Link Download Remove Duplicates from Sorted list II Java “.

Thảo Luận vướng mắc về Remove Duplicates from Sorted list II Java

Bạn trọn vẹn có thể để lại Comment nếu gặp yếu tố chưa hiểu nghen.
#Remove #Duplicates #Sorted #list #Java

Phương Bách

Published by
Phương Bách