刪除鍊錶中重複的的數字

2021-10-11 11:41:13 字數 552 閱讀 3909

這是我面試美團時候考的題目,在牛客網j56,對於鍊錶在我們大學的第一次學資料結構就接觸了,但是不能說處理這種題目很容易。面試就是這種套路,當面試官覺得你的專案沒什麼亮點時,就會考察你的演算法能力。

廢話少說,先上**

public class solution 

listnode head=new listnode(-1);

head.next=phead;

listnode pre=head;

listnode cur=head.next;

while(cur!=null)

cur=cur.next;

pre.next=cur;

}else

}return head.next;

}

}

隨便說說自己對於,這道題目的理解吧。演算法題-無非就是while、if等條件。要想刪除鍊錶的中的重複元素,就需要將前面的元素與後面的元素進行值的比較,寫出if(phead.val==phead.next.val),如果條件成立,就要需要將重複的資料進行刪除,這裡

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

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

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

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

LintCode 刪除排序鍊錶中的重複數字 II

題目描述 給定乙個排序鍊錶,刪除所有重複的元素只留下原煉表中沒有重複的元素。樣例 給出 1 2 3 3 4 4 5 null,返回 1 2 5 null 給出 1 1 1 2 3 null,返回 2 3 null 思路分析 ac definition of listnode class listno...