[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 ...
随机推荐
- Flo's Restaurant[HDU1103]
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ3118 : Orz the MST
对于树边显然只需要减少权值,对于非树边显然只需要增加权值 设i不为树边,j为树边 X[i]:i增加量 X[j]:j减少量 C[i]:修改1单位i的代价 对于每条非树边i(u,v),在树上u到v路径上的 ...
- TYVJ P1067 合唱队形 Label:上升子序列?
背景 NOIP2004 提高组 第三道 描述 N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学排成合唱队形. 合唱队形是指这样的一种队形:设K位同学从左到右依次编号 ...
- Java之美[从菜鸟到高手演变]之HashMap、HashTable(转载)
http://blog.csdn.net/zhangerqing/article/details/8193118
- 【COGS】147. [USACO Jan08] 架设电话线(二分+spfa)
http://cojs.tk/cogs/problem/problem.php?pid=147 学到新姿势了orz 这题求的是一条1-n的路径的最大路径最小. 当然是在k以外的. 我们可以转换一下. ...
- UOJ#77. A+B Problem
题目名称是吸引你点进来的. 从前有个 n 个方格排成一行,从左至右依此编号为 1,2,⋯,n. 有一天思考熊想给这 n 个方格染上黑白两色. 第 i 个方格上有 6 个属性:ai,bi,wi,li,r ...
- JavaScript事件大全3
//无模式的提示框 //屏蔽按键 <html> <head> <meta http-equiv="Content-Type" content=& ...
- hdu Train Problem I
这道题是道简单的栈模拟题,只要按照真实情况用栈进行模拟即可: #include<stdio.h> #include<string.h> #include<stack> ...
- switch,break和default语句练习
int w = 8; switch (w){ case 0: System.out.println("今天是星期日"); break; case 1: System.out.pri ...
- EasyUI datagrid 在ie8和360兼容模式兼容性问题
问题:easyui中的datagrid在ie8和360兼容模式下显示不出来. 答案:不是easyui的问题.是引入的jquery版本问题.jquery-1.5.1抛异常,这个版本是mvc3自带的jqu ...