Leetcode 83 删除排序链表中的重复元素 (每日一题 20210804)
生活随笔
收集整理的這篇文章主要介紹了
Leetcode 83 删除排序链表中的重复元素 (每日一题 20210804)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
存在一個按升序排列的鏈表,給你這個鏈表的頭節點 head ,請你刪除所有重復的元素,使每個元素 只出現一次 。返回同樣按升序排列的結果鏈表。示例 1:輸入:head = [1,1,2]
輸出:[1,2]
示例 2:輸入:head = [1,1,2,3,3]
輸出:[1,2,3]鏈接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-listclass Solution:def deleteDupilcate(self,head:ListNode):->ListNode:if not head:return headcur = headwhile cur.next:if cur.val == cur.next.val:cur.next = cur.next.nextelse:cur = cur.nextreturn head
總結
以上是生活随笔為你收集整理的Leetcode 83 删除排序链表中的重复元素 (每日一题 20210804)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 300 最长递增子序列
- 下一篇: Leetcode 69 x的平方根 (每