admin 管理员组文章数量: 1087749
[勇者闯LeetCode] 83. Remove Duplicates from Sorted List
[勇者闯LeetCode] 83. Remove Duplicates from Sorted List
Description
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given1->1->2
, return1->2
.
Given1->1->2->3->3
, return1->2->3
.
Information
- Tags: Linked List
- Difficulty: Easy
Solution
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = Noneclass Solution(object):def deleteDuplicates(self, head):""":type head: ListNode:rtype: ListNode"""ans = headwhile ans is not None and ans.next is not None:if ans.next.val == ans.val:ans.next = ans.next.nextelse:ans = ans.nextreturn head
本文标签: 勇者闯LeetCode 83 Remove Duplicates from Sorted List
版权声明:本文标题:[勇者闯LeetCode] 83. Remove Duplicates from Sorted List 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1694408301a251714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论