T83 删除排序链表中的重复元素

桌桌 2022-8-12 194 8/12

题目描述如下:

T83 删除排序链表中的重复元素

解题思路:

每一个检查一下,一直到链表最后就好啦

代码如下:

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
   def deleteDuplicates(self, head: ListNode) -> ListNode:
       p = head
       p_aft = head
       if p is None or p.next is None:
           return p
       else:
           p_aft == p.next
       while p_aft != None:
           if p.val == p_aft.val:
               p.next = p_aft.next
               p_aft = p_aft.next
           else:
               p = p.next
               p_aft = p_aft.next
       
       return head

结果如下:

T83 删除排序链表中的重复元素

- THE END -

桌桌

8月16日01:08

最后修改:2022年8月16日
0

非特殊说明,本博所有文章均为博主原创。

共有 6 条评论

  1. russian bet

    Wonderful article! We will be linking to this particularly great content on our website. Keep up the great writing. Elisha Geter

  2. bitcoin

    Excellent article. I am facing a few of these issues as well.. Dario Durk

  3. freespin

    Hi there mates, pleasant article and pleasant arguments commented at this place, I am genuinely enjoying by these. Boyd Mcannally

  4. passwords

    There is definately a great deal to find out about this topic. I like all the points you made. Theron Goodwyn

  5. Looking for sex tonight in your area

    Dead pent content , thanks for selective information . Boyd Halberstam

  6. sikis

    Only wanna input that you have a very decent web site , I enjoy the style it actually stands out. Marcellus Racioppi