刪除鍊錶中重複的節點。

2021-08-08 20:00:52 字數 437 閱讀 5973

本題源自劍指offer

要刪除重複的節點,既要保留重複節點的前乙個節點和後乙個節點,然後讓前乙個節點指向後乙個節點。

listnode* deleteduplication(listnode* phead)

if(flag)

if(pre==null)else

p=pnext;

}else

}return phead;

}**2構造頭結點,然後再刪除

listnode* deleteduplication(listnode* phead)

if(pre->next!=p)else

}phead=head->next;

delete head;

head=null;

return phead;

}

鍊錶 刪除鍊錶中重複的節點

刪除鍊錶中重複的節點 方法一 採用遞迴的方法,但這種方法在鍊錶無重複節點時效率不高 function deleteduplication phead if phead.val phead.next.val return deleteduplication node 採用遞迴的方法從下乙個不重複的點開...

鍊錶 刪除鍊錶中重複的節點

刪除鍊錶中重複的節點 方法一 採用遞迴的方法,但這種方法在鍊錶無重複節點時效率不高 function deleteduplication phead if phead.val phead.next.val return deleteduplication node 採用遞迴的方法從下乙個不重複的點開...

刪除鍊錶中重複的節點

題目描述 在乙個排序的鍊錶中,存在重複的結點,請刪除該鍊錶中重複的結點,重複的結點不保留,返回煉表頭指標。例如,鍊錶1 2 3 3 4 4 5 處理後為 1 2 5 這個題目首先考慮到頭結點也可能是重複的節點,所以需要設定乙個頭結點之前的節點。之後需要3個指標 pre,cur和next struct...