LeetCode Linked List Easy 83. Remove Duplicates from Sorted List
Posted C_supreme
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode Linked List Easy 83. Remove Duplicates from Sorted List相关的知识,希望对你有一定的参考价值。
Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
Input: 1->1->2 Output: 1->2Example 2:
Input: 1->1->2->3->3 Output: 1->2->3
问题描述:给定一个已排序链表,移除重复元素
代码:
public ListNode DeleteDuplicates(ListNode head) { ListNode l = head; while(l != null && l.next != null){ if(l.val == l.next.val){ l.next = l.next.next; }else{ l = l.next; } } return head; }
以上是关于LeetCode Linked List Easy 83. Remove Duplicates from Sorted List的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode] 203. Remove Linked List Elements_Easy tag: Linked LIst
[LeetCode] 876. Middle of the Linked List_Easy tag: Linked List
LeetCode 234. 回文链表 Palindrome Linked List (Easy)
(Easy) Delete Node in a Linked List - LeetCode
LeetCode Linked List Easy 83. Remove Duplicates from Sorted List