class ListNode:
def __init__(self,x):
self.val=x
self.next=None
####注意这道题并不是把重复元素全部去掉而是保留一个#### #####solution1##########
class Solution:
def deleteDuplicates(self, head):
res=[]
p=ListNode(0)
q=p
while head:
if head.val not in res:
res.append(head.val)
head=head.next
for i in res:
node=ListNode(i)
p.next=node
p=p.next
return q.next
######solution2####faster####
class Solution:
def deleteDuplicates(self, head):
dummy_head = ListNode("*")
prev_node = dummy_head
while head:
if head.val != prev_node.val:
prev_node.next = head
prev_node = head
head = head.next
prev_node.next = None
return dummy_head.next

  

083_Remove Duplicates from Sorted List的更多相关文章

  1. [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  2. [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  3. [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

  4. [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  5. Leetcode-83 Remove Duplicates from Sorted List

    #83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that ...

  6. Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...

  7. Remove Duplicates From Sorted Array

    Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...

  8. 【leetcode】Remove Duplicates from Sorted Array II

    Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...

  9. 26. Remove Duplicates from Sorted Array

    题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...

随机推荐

  1. threejs学习笔记(一)

    得到webgl的渲染管线

  2. Java中a+=b和a=a+b的区别

    在Java语言中a+=b和a=a+b是有区别的,主要的区别是在运算时精度的问题,当然了-=.*=./=,%=也都是一个道理.这里以a+=b和a=a+b为例做说明. (1)下面以一段Java程序为例,试 ...

  3. 查看jar包的jdk版本

  4. UVALive - 5135 - Mining Your Own Business(双连通分量+思维)

    Problem   UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...

  5. 【css3】使用filter属性实现改变svg图标颜色

    1.兼容性: 2.应用场景:新增页面上传svg图标后,更改图标颜色后,在列表页面展示色值改后的svg图标. 3.解决方案:使用filter属性中的 drop-shadow,drop-shadow滤镜可 ...

  6. @EnableWebMvc,WebMvcConfigurationSupport,WebMvcConfigurer和WebMvcConfigurationAdapter区别

    @EnableWebMvc是什么 直接看源码,@EnableWebMvc实际上引入一个DelegatingWebMvcConfiguration. @Retention(RetentionPolicy ...

  7. Redis入门---字符串类型

    阅读目录 1.keys * 命令 2.判断一个键是否存在(exists key) 3.删除键 4.获取键值的数据类型 5 递增数字(incr) 6.增加指定的整数 (INCRBY) 7.减少指定的整数 ...

  8. devmem读写物理内存和devkmem读取内核虚拟内存

    关键词:/dev/mem./dev/kmem.mmap.__va.__pa.remap_pfn_range等等. 在日常工作中常有直接操作寄存器或者某一物理地址的需求,busybox中提供了devme ...

  9. 在pycharm中查看内建函数源码

    鼠标放在内建函数上,Ctrl+B,看源码

  10. ExcelDna项目完整工程演示及讲解

    原始链接:http://www.cnblogs.com/Charltsing/p/ExcelDnaDemo.html ExcelDna工程演示讲课内容 1.ExcelDna是啥? 2.ExcelDna ...