Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 566 Bytes

83.md

File metadata and controls

20 lines (17 loc) · 566 Bytes

LeetCode 83 Remove Duplicates from Sorted List——easy

Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
Input: 1->1->2
Output: 1->2

Example 2:
Input: 1->1->2->3->3
Output: 1->2->3
思路:
1、如果当前节点和下一个节点的val相等,则删除此重复节点、即当前节点指向下下个节点
2、如果不相等、则p = p.next
3、循环的条件是当前节点不为空 && 下一个节点也不为空