Leetcode-Remove Duplicates from Sorted List-Python
来源:互联网 发布:十颗心大数据 编辑:程序博客网 时间:2024/06/06 04:02
Remove Duplicates from Sorted List
从排序链表中删除重复元素。
Description
解题思路:
依次比较相邻的两个链表元素,若值相等,则将前一个节点的next引用为后一个节点的后一个节点。使用cur来依次向下遍历元素,最后返回head。
# 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 """ cur = head while cur: while cur.next and cur.next.val==cur.val: cur.next = cur.next.next cur = cur.next return head
阅读全文
0 0
- Leetcode-Remove Duplicates from Sorted List-Python
- 【Leetcode】【python】Remove Duplicates from Sorted List/Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- 【LeetCode with Python】 Remove Duplicates from Sorted List
- 【LeetCode with Python】 Remove Duplicates from Sorted List II
- Python学习——leetcode(Remove Duplicates from Sorted List)
- 【leetcode OJ】Remove Duplicates from Sorted List(python)
- 83. Remove Duplicates from Sorted List Leetcode Python
- 82. Remove Duplicates from Sorted List II Leetcode Python
- 【LEETCODE】82- Remove Duplicates from Sorted List II [Python]
- [leetcode:python]83.Remove Duplicates from Sorted List
- 链表-python-leetcode 83 Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List
- POJ-1985 树的最长路径
- 10个最佳ES6特性
- Qt Quick元素布局
- Mysql 数据库date, datetime类型设置0000-00-00默认值报错问题
- Python使用seaborn包之路——下载包、更新anaconda3、jupyter notebook切换Python3
- Leetcode-Remove Duplicates from Sorted List-Python
- 输入挂
- CSS3 选择器浏览器兼容性汇总 IE8
- MySQL LOAD DATA INFILE 导入 CSV 格式数据
- leetcode(56). Merge Intervals
- 音乐类App原型制作分享-Qello Concerts
- neural networks deep learning Python Basics with numpy (optional) Homework
- android应用开发-从设计到实现 4-7天气详情的布局
- Divide Two Integers LeetCode 解题报告