83. Remove Duplicates from Sorted List
来源:互联网 发布:知乎辩护人一样的电影 编辑:程序博客网 时间:2024/06/16 00:58
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
c++实现
ListNode* deleteDuplicates(ListNode* head) { ListNode* cur = head; while(cur) { while(cur->next && cur->val == cur->next->val) { cur->next = cur->next->next; } cur = cur->next; } return head; }
python实现
# 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 """ p = head while p and p.next: if p.val == p.next.val: p.next = p.next.next else: p = p.next return head
阅读全文
0 0
- [LeetCode]83.Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- [Leetcode] 83. Remove Duplicates from Sorted List
- LeetCode --- 83. Remove Duplicates from Sorted List
- [leetcode] 83.Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List LeetCode
- 83. Remove Duplicates from Sorted List
- leetcode 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- [LeetCode]83. Remove Duplicates from Sorted List
- 【LeetCode】83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- Linux个人用户安装JDK(与root用户不同版本)
- [转]C++模板
- 电脑无法识别(读取)U盘
- 《图解HTTP》整理(7)
- Ceph架构介绍及使用
- 83. Remove Duplicates from Sorted List
- maven学习笔记(八)maven的生命周期
- Anaconda 离线安装 python 包方法
- MySQL无限分类表设计
- 斐波那契数列求兔子总数
- 十大机器学习算法----下篇
- 保留关键字的概念
- 目前市面上最好的HDMI转EDP解决方案-NCS8803
- HDU 4803Poor Warehouse Keeper(数学题)