[leetcode]Remove Duplicates from Sorted List @ Python
原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/
题意:
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
.
解题思路:链表节点的去重。比较简单。
代码:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None class Solution:
# @param head, a ListNode
# @return a ListNode
def deleteDuplicates(self, head):
if head == None or head.next == None:
return head
p = head
while p.next:
if p.val == p.next.val:
p.next = p.next.next
else:
p = p.next
return head
[leetcode]Remove Duplicates from Sorted List @ Python的更多相关文章
- leetcode Remove Duplicates from Sorted Array python
class Solution(object): def removeDuplicates(self,nums): if len(nums) <= 0: return 0 j=0 for i in ...
- LeetCode:Remove Duplicates from Sorted List I II
LeetCode:Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such t ...
- LeetCode:Remove Duplicates from Sorted Array I II
LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...
- [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- [Leetcode] Remove Duplicates From Sorted Array II (C++)
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- Leetcode: Remove Duplicates from Sorted List II 解题报告
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
随机推荐
- Orleans安装
一.Nuget包Orleans NuGet软件包从v1.5.0开始在大多数情况下,您需要使用4个关键的NuGet包: 1,Microsoft Orleans Build-time Code Gener ...
- BZOJ4042 : [Cerc2014] parades
设f[x]为x子树里能选的最多的路径数,h[x]为x子树里往上走的点的集合,且不与x子树内的最优解冲突 首先f[x]=sum(f[son]) 若h[son]与x可以直接匹配,则匹配上,f[x]++ 然 ...
- 设置java.library.path的值(Mac/Linux/Windows)
说明:网上基本针对这个值的设置分为两面,Windows派和Linux派,Windows的不说,Linux下只会说设置LD_LIBRARY_PATH即可,但这种方式在Java 8是一个错误的设置,尤其是 ...
- 使用winrar自解压功能制作安装包
参考文献: bat脚本设置文件的只读属性:http://wenda.tianya.cn/question/0f484c28ffd8d4e9 bat脚本创建internet快捷方式:http://www ...
- VS2008 LINK : fatal error LNK1104: cannot open file 'atls.lib'错误解决方案
用VS 2008编写ATL的64位应用程序时,提示链接错误:VS2008 LINK : fatal error LNK1104: cannot open file 'atls.lib' 问题原因 VS ...
- 关于pcie的备忘
总线驱动:深度优先统计资源,深度滞后分配资源 资源包括Bus id和内存(prefectable和non-prefectable内存) 设备驱动:包括设备驱动层和消息通信 主要是四个部分: (1)中断 ...
- eclipse使用profile完成不同环境的maven打包功能
原文:https://blog.csdn.net/duan9421/article/details/79086335 我们在日常开发工作中通常会根据不同的项目运行环境,添加不同的配置文件,例如 开发环 ...
- rtorrent - 强大的命令行BT客户端
NOTE - 文中展示的所有示例和指令都已经在Ubuntu 13.04中测试过. 一. 安装 [root@GY-10000 data]# yum search rtorrent ...
- __NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance
同样是删除cell问题,帮我看看问题出现在哪,谢谢! 我的类文件myFile是继承UIViewController的(目的是为了能够在一个view里切换不同的tableView),在myFile.h中 ...
- Android 和 iOS 应用程序开发对比 [持续更新]
1.Android 用字典模式统一管理应用程序中UI上用到的所有字符串. 比如文本框的默认文本.按钮的名字等等.表现形式:XML文件 Android中 "@string/text_filed ...