【LeetCode從零單排】No83 Remove Duplicates from Sorted List
題目
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
程式碼
public static ListNode deleteDuplicates(ListNode head) {
if (head==null || head.next==null) return head;
ListNode first = head;
ListNode second=head.next;
while(second!=null){
if(first.val==second.val){
second=second.next;
first.next=second;
}
else{
first=first.next;
second=first.next;
}
}
return head;
}
/********************************
* 本文來自部落格 “李博Garvin“
* 轉載請標明出處:http://blog.csdn.net/buptgshengod
******************************************/
相關文章
- 【LeetCode從零單排】No26.Remove Duplicates from Sorted ArrayLeetCodeREM
- Leetcode Remove Duplicates from Sorted ListLeetCodeREM
- Remove Duplicates from Sorted ListREM
- Leetcode Remove Duplicates from Sorted List IILeetCodeREM
- Leetcode-Remove Duplicates from Sorted ListLeetCodeREM
- Remove Duplicates from Sorted List leetcode javaREMLeetCodeJava
- Remove-duplicates-from-sorted-listREM
- LeetCode 83. Remove Duplicates from Sorted ListLeetCodeREM
- 【Leetcode】83. Remove Duplicates from Sorted ListLeetCodeREM
- Leetcode-Remove Duplicates from Sorted List IILeetCodeREM
- Remove Duplicates from Sorted List II leetcode javaREMLeetCodeJava
- 83. Remove Duplicates from Sorted ListREM
- 【Leetcode】82. Remove Duplicates from Sorted List IILeetCodeREM
- 82. Remove Duplicates from Sorted List IIREM
- leetcode Remove Duplicates from Sorted ArrayLeetCodeREM
- Leetcode 26 Remove Duplicates from Sorted ArrayLeetCodeREM
- Leetcode Remove Duplicates from Sorted Array IILeetCodeREM
- Leetcode-Remove Duplicates from Sorted ArrayLeetCodeREM
- Remove Duplicates from Sorted Array leetcode javaREMLeetCodeJava
- [leetcode]remove-duplicates-from-sorted-array-iiLeetCodeREM
- Leetcode-Remove Duplicates from Sorted Array IILeetCodeREM
- Remove Duplicates from Sorted Array II leetcode javaREMLeetCodeJava
- Remove-duplicates-from-sorted-arrayREM
- [LeetCode] 80. Remove Duplicates from Sorted Array IILeetCodeREM
- 26. Remove Duplicates from Sorted ArrayREM
- LeetCode 83.Remove Duplicates from Sorted List(從已排序連結串列中除去重複) Easy/Linked ListLeetCodeREM排序
- Remove Duplicates from Sorted List 去除連結串列中重複值節點REM
- [LeetCode] Remove Duplicates from Sorted Array 有序陣列中去除重複項LeetCodeREM陣列
- 【LeetCode從零單排】No27.Remove ElementLeetCodeREM
- 【LeetCode從零單排】No88.Merge Sorted ArrayLeetCode
- 【leetcode】26. Remove Duplicates from Sorted Array 刪除有序陣列的重複元素LeetCodeREM陣列
- Leetcode Remove Nth Node From End of ListLeetCodeREM
- Leetcode 19 Remove Nth Node From End of ListLeetCodeREM
- Leetcode-Remove Nth Node From End of ListLeetCodeREM
- Remove Nth Node From End of List leetcode javaREMLeetCodeJava
- leetcode19:Remove Nth Node From End of ListLeetCodeREM
- [LeetCode] 2487. Remove Nodes From Linked ListLeetCodeREM
- 【LeetCode從零單排】No 114 Flatten Binary Tree to Linked ListLeetCode