[LeetCode]题解(python):083 - Remove Duplicates from Sorted List
题目来源
https://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
.
题意分析
Input:
:type head: ListNode
Output:
:rtype: ListNode
Conditions:一个有序list,删除掉重复的元素
题目思路
每次判断增加一个节点时,看是否与当前结点重复,重复则跳过
AC代码(Python)
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None class Solution(object):
def deleteDuplicates(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head == None or head.next == None:
return head
p = head
while p.next != None:
if p.val == p.next.val:
p.next = p.next.next
else:
p = p.next
return head
[LeetCode]题解(python):083 - Remove Duplicates from Sorted List的更多相关文章
- [Leetcode][Python]26: Remove Duplicates from Sorted Array
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...
- LeetCode之“链表”:Remove Duplicates from Sorted List && Remove Duplicates from Sorted List II
1. Remove Duplicates from Sorted List 题目链接 题目要求: Given a sorted linked list, delete all duplicates s ...
- <LeetCode OJ> 83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted List Total Accepted: 94387 Total Submissions: 264227 Difficulty: E ...
- leetCode练题——26. Remove Duplicates from Sorted Array
1.题目 26. Remove Duplicates from Sorted Array--Easy Given a sorted array nums, remove the duplicates ...
- LeetCode(80)Remove Duplicates from Sorted Array II
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- 083. Remove Duplicates from Sorted List
题目链接:https://leetcode.com/problems/rotate-list/description/ Given a sorted linked list, delete all d ...
- Java for LeetCode 083 Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- leetcode第26题--Remove Duplicates from Sorted Array
problem: Given a sorted array, remove the duplicates in place such that each element appear only onc ...
- 【LeetCode算法-26】Remove Duplicates from Sorted Array
LeetCode第26题 Given a sorted array nums, remove the duplicates in-place such that each element appear ...
随机推荐
- BZOJ3711 : [PA2014]Druzyny
设f[i]为[1,i]分组的最优解,则 f[i]=max(f[j]+1),max(c[j+1],c[j+2],...,c[i-1],c[i])<=i-j<=min(d[j+1],d[j+2 ...
- u盘文件系统故障的修复方法
比如U盘挂载的文件系统是/dev/sda1,且文件系统有故障(FAT: Filesystem error) 修复U盘文件系统故障 sudo dosfsck -v -a /dev/sda1
- IntelliJ IDEA 14 SVN无法正常使用问题
通过SVN导入项目 SVN checkout时候会出现如下错误: Cannot run program "svn" (in directory "E:\Projects& ...
- <!--[if IE]>….<![endif]--> (<!--[if !IE]>||<![endif]-->)的用法
1. <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--> 2. <!--[if IE]> 所有的IE可识别 ...
- meta标签的用法
meta是用来在HTML文档中模拟HTTP协议的响应头报文.meta 标签用于网页的<head>与</head>中,meta 标签的用处很多.meta 的属性有两种:name和 ...
- STL各种容器的使用时机详解
C++标准程序库提供了各具特长的不同容器.现在的问题是:该如何选择最佳的容器类别?下表给出了概述. 但是其中有些描述可能不一定实际.例如:如果你需呀处理的元素数量很少,可以虎落复杂度,因为线性算法通常 ...
- 常用的一些webshell木马官方后门
80SEC剑心修改过世界杀毒版 http://wwwxx.cn/1.asp?web2a2dmin=//?web2a2dmin=//1.asp 绕过 不灭之魂的后门 1.在错误页面右键可以查看密码 2 ...
- echo "不允许上传该类型的文件
<?php教程 // 上传设置 $maxsize=10002400; //最大允许上传的文件大小 $alltype=array(".php"," ...
- 在Windows上启用LDAPs
公司的环境比较特殊, Windows server + Linux desktop, 所以我们希望在server端启用LDAP over SSL功能. 当中走了不少弯路, 网上文章也搜了一大堆, 千辛 ...
- checked Exception和unchecked exception
checked Exception: io,sql等exception,程序无法控制的 unchecked exception: 包括Error与RuntimeException及其子类,如:OutO ...