LeetCode subject
Given a sort list , Delete all nodes with duplicate numbers , Keep only the original linked list No recurrence The number of .
Example :
input : 1->2->3->3->4->4->5
output : 1->2->5
Algorithmic idea
1. Create a virtual node , Connect all non repeating nodes to the back
2. definition cur Ergodic single chain table , Judge whether the number of current node and next node is the same
3. Return to new single chain table
code
class Solution { public ListNode deleteDuplicates(ListNode head) { if(head==
null||head.next==null){ return head; } ListNode node=new ListNode(-1); ListNode
tmp=node; ListNode cur=head; while(cur!=null){ if(cur.next!=null&&cur.val==cur.
next.val){ while(cur.next!=null&&cur.val==cur.next.val){ cur=cur.next; } cur=cur
.next; }else{ tmp.next=cur; cur=cur.next; tmp=tmp.next; } } tmp.next=null;
return node.next; } }

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Some East 14 Pay change 16 salary , Sincerity or routine ? Browser kernel ( understand )java Four functional interfaces ( a key , simple )HashMap Explain in detail html Writing about cherry trees , Writing about cherry trees os Simple use of module