劍指Offer 刪除鍊錶中重複的結點

2021-09-19 13:51:20 字數 532 閱讀 5144

在乙個排序的鍊錶中,存在重複的結點,請刪除該鍊錶中重複的結點,重複的結點不保留,返回煉表頭指標。 例如,鍊錶1->2->3->3->4->4->5 處理後為 1->2->5

題解

#include

using

namespace std;

struct listnode

listnode()

};listnode *

newlist()

q->next =

null

;return l-

>next;

}void

print

(listnode *phead)

}listnode *

deleteduplication

(listnode *phead)

return

deleteduplication

(pnode);}

else

}int

main()

劍指offer 鍊錶 刪除鍊錶中的重複節點

題目在乙個排序的鍊錶中,存在重複的結點,請刪除該鍊錶中重複的結點,重複的結點不保留,返回煉表頭指標。例如,鍊錶1 2 3 3 4 4 5 處理後為 1 2 5 思路分析 思路一 使用linkedlist儲存不重複節點,重構鍊錶 分析評價 這個方法是乙個比較直接且容易想到的方法,使用時只要注意一些情況...

劍指offer 刪除鍊錶中重複的結點(鍊錶)

在乙個排序的鍊錶中,存在重複的結點,請刪除該鍊錶中重複的結點,重複的結點不保留,返回煉表頭指標。例如,鍊錶1 2 3 3 4 4 5 處理後為 1 2 5 class solution listnode ans newlistnode 1 ans next phead listnode link a...

劍指Offer 鍊錶 刪除鍊錶中重複的結點

題目 在乙個排序的鍊錶中,存在重複的結點,請刪除該鍊錶中重複的結點,重複的結點不保留,返回煉表頭指標。例如,鍊錶1 2 3 3 4 4 5 處理後為 1 2 5。注意該鍊錶為排序鍊錶,重複的節點不保留哦!public class listnode 1 遞迴 遞迴的方法就像是先判斷第乙個節點和之後的節...