leetcode83
/**
* Definition for singly-linked list.
* public class ListNode {
* public int val;
* public ListNode next;
* public ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode DeleteDuplicates(ListNode head)
{
//if (head == null || head.next == null)
//{
// return head;
//}
//head.next = DeleteDuplicates(head.next); //if (head.val == head.next.val)
//{
// return head.next;
//}
//else
//{
// return head;
//} if (head != null)
{
var cur = head;
var next = head.next;
while (next != null)
{
if (cur.val == next.val)
{
cur.next = next.next;//对原链表的修改
}
else
{
cur = next;//移动指针
}
next = next.next;//移动指针
}
}
return head;
}
}
https://leetcode.com/problems/remove-duplicates-from-sorted-list/#/description
补充一个python的实现:
class Solution:
def deleteDuplicates(self, head: ListNode) -> ListNode:
if head == None:
return None
cur = head
nextnode = head.next
while nextnode != None:
if cur.val == nextnode.val:
cur.next = nextnode.next
else:
cur = nextnode
nextnode = nextnode.next
return head
leetcode83的更多相关文章
- leetcode-83.删除排序链表中的重复元素
leetcode-83.删除排序链表中的重复元素 Points 链表 题意 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1- ...
- Leetcode-83 Remove Duplicates from Sorted List
#83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that ...
- leetcode83,删除有序链表中的重复元素
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- [Swift]LeetCode83. 删除排序链表中的重复元素 | Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...
- leetCode83. 删除排序链表中的重复元素
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示例 2: 输入: 1->1->2->3-&g ...
- LeetCode83.删除排序链表中的重复的元素
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示例 2: 输入: 1->1->2->3-&g ...
- leetcode83 Remove Duplicates from Sorted List
题意:删掉单链表里重复的节点,如:Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2 ...
- LeetCode链表解题模板
一.通用方法以及题目分类 0.遍历链表 方法代码如下,head可以为空: ListNode* p = head; while(p!=NULL) p = p->next; 可以在这个代码上进行修改 ...
随机推荐
- javascript的单例模式
单例模式是javascript最基本,最有用的模式之一,它提供了一种将代码组织为一个逻辑单元的手段,这个逻辑单元中的代码通过单一的变量进行访问.我的理解是在这个作用域中,只有通过单一的变量来访问,不存 ...
- event store
Event Store The documentation has now moved to the wiki in this repository. For a quick start, look ...
- PHP com组件的使用 (环境搭建 以及测试)
COM 组件在实际当前的软件开发中依然是比较重要,包括对于串口开发的人员,软件插件使用的人员,PHP 已经为我们添加了对于 COM的支持,可以很好的解决我们在开发中可能碰到的一些问题.一下是开发环境的 ...
- CGI之C语言篇
为什么要进行CGI编程? 在HTML中,当客户填写了表单,并按下了发送(submit)按钮后,表单的内容被发送到了服务器端,一般的,这时就需要有一个服务器端脚本来对表单的内容进行一些处理,或者是把它们 ...
- FastAdmin 自己做的插件 SQL 有一个表没有生成成功
群里有群友问: 给插件建的install.sql 里有三个表,为啥会出现安装成功后没有错误提示,只生成了两个表的情况..这可能会是什么...原因 第一感觉和 FastAdmin 没有关系. 没生成表, ...
- mave安装配置
首先从官网上 http://maven.apache.org/ 下载最新版Maven.我用的是apache-maven-3.0.4-bin.tar.gz.将下载后的文件拷贝到 /usr/local/目 ...
- Visual Studio2010不能安装Silverlight4_Tools,提示语言不一致
天在装Silverlight4_Tools时出现“必须先安装与 Silverlight Tools 4 语言版本相一致的 Visual Studio 2010.Visual Web Developer ...
- POJ1135 Domino Effect
题目:http://poj.org/problem?id=1135 只是求以1为起点的最短路罢了.稍稍判断一下在边上的情况. 多亏提醒:毒数据——n==1!一定要dis [ k ] >= ans ...
- spring mvc 工作原理
SpringMVC的工作原理图: SpringMVC流程 1. 用户发送请求至前端控制器DispatcherServlet. 2. DispatcherServlet收到请求调用HandlerMa ...
- SpringCloud初体验:七、gateway 网关服务如何做token验证
说说背景:假如有一个用户服在用户登录后,生成一个token给到客户端,用户每次请求时都需要这个token,于是每次都会在网关 gateway 校验,校验通过后网关从token中解析出userId,然后 ...