[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 ...
随机推荐
- odoo12主题样式模块
odoo12主题样式模块 图标形式显示菜单目录的结构 odoo12图标形式显示菜单:https://apps.odoo.com/apps/themes/12.0/backend_theme_v12/ ...
- 添加第一个控制器(Controllers)
在MVC体系架构中,输入请求是由控制器Controller来处理的(负责处理浏览器请求,并作出响应).在ASP.NET MVC中Controller本身是一个类(Class)通常继承于System.W ...
- 【WIN10】WIN2D——基本圖形的繪製
DEMO下載地址:http://yunpan.cn/c3iNuHFFAcr8h (提取码:8e48) 先看一個截圖: 繪製了一些基本形狀. DEMO的繪製代碼都非常簡單,不想在博客裡細說了,看代碼更為 ...
- hadoop 视频教程2
Hadoop大数据零基础实战培训教程 一,教程内容: 1,Hadoop2.0YARN深入浅出系列 2,Avro数据序列化系统 3,Chukwa集群监控系统 4,Flume日志收集系统 5,Greenp ...
- Ural 2045. Richness of words 打表找规律
2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...
- Linux学习笔记03—初识Linux
命令介绍 忘记root密码的处理方法 系统安装盘的救援模式的使用 一.命令介绍 1.LS命令 ls 查看当前目录下的文件 Ls –l 等同于ll 查看目录的详细信息 Ls –a 查看当前目录下的所有文 ...
- Ubuntu 16.04实现SSH无密码登录/免密登录/自动登录(ssh-keygen/ssh-copy-id)
ssh-keygen:产生公钥与私钥(在~/.ssh) ssh-copy-id:将本机的公钥复制到远程机器的authorized_keys文件中(在~/.ssh),ssh-copy-id也能让你有到远 ...
- LPC43xx双核笔记
简介本页提供了一些使用LPC43xx器件双核特性的基本信息.此页面上的信息和专题使用Keil uVision4工具,以双核工程的使用来演示.该工程初始化两个内核以运行FreeRTOS,并采用三色LED ...
- GO语言基础之method
方法 method 1. Go 中虽没有 class,但依旧有 method 2. 通过显示说明 receiver 来实现与某个类型的组合 3. 只能为同一个包中的类型定义方法 4. Receiver ...
- MyEclipse10安装Log4E插件
一. Log4E插件下载 下载地址:http://log4e.jayefem.de/content/view/3/2/ 二.安装Log4E插件 将下载下来的压缩包解压缩,如下图所示: 解压缩生成的[d ...