哈哈,我又来了。昨天发现题目太简单就没有放上来,今天来了一道有序链表的题。题目如下:

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.

题目分析:简单来说就是去除有序链表中重复的值。

代码实现:

ListNode:

 public class ListNode {
int val;
ListNode next; ListNode(int x) {
val = x;
}
}

具体代码实现:

 public static ListNode deleteDuplicates(ListNode head) {

         if (head != null) {

             if (head.next != null) {
if (head.val == head.next.val) {//如果值相等
head.next = head.next.next;//让他后面的指向后面的后面
deleteDuplicates(head);//再次进行比较
} else {
deleteDuplicates(head.next);
}
} } return head;
}

总体来说还是比较简单,一次ac,哈哈。

leetcode修炼之路——83. Remove Duplicates from Sorted List的更多相关文章

  1. LeetCode Linked List Easy 83. Remove Duplicates from Sorted List

    Description Given a sorted linked list, delete all duplicates such that each element appear only onc ...

  2. leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)

    203题是在链表中删除一个固定的值,83题是在链表中删除重复的数值,但要保留一个:82也是删除重复的数值,但重复的都删除,不保留. 比如[1.2.2.3],83题要求的结果是[1.2.3],82题要求 ...

  3. <LeetCode OJ> 83. Remove Duplicates from Sorted List

    83. Remove Duplicates from Sorted List Total Accepted: 94387 Total Submissions: 264227 Difficulty: E ...

  4. 83. Remove Duplicates from Sorted List【easy】

    83. Remove Duplicates from Sorted List[easy] Given a sorted linked list, delete all duplicates such ...

  5. [LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项

    Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...

  6. 【一天一道LeetCode】#83. Remove Duplicates from Sorted List

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  7. 【leetcode刷题笔记】Remove Duplicates from Sorted List II

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  8. 【Leetcode】【Medium】Remove Duplicates from Sorted Array II

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

  9. 【leetcode刷题笔记】Remove Duplicates from Sorted Array II

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

随机推荐

  1. Delphi判断文件是否正在被使用(CreateFile也可以只是为了读取数据,而不是创建)

    首先,我们先来认识下CreateFile函数,它的原型如下   HANDLE CreateFile( LPCTSTR lpFileName,    //指向文件名的指针 DWORD dwDesired ...

  2. AlgorithmsI Exercises: Analysis of Algorithms

    Question 1 Suppose that you time a program as a function of N and producethe following table. N seco ...

  3. matlab中如何求某一个矩阵的标准差和均值

    方法: 先reshape成行向量或者列向量 然后,利用mean函数,std函数. 构造测试数据,可以利用random函数,就好.利用这个函数,可以构造不同分布的随机数列(或 矩阵). 如: >& ...

  4. HDU 5452 Minimum Cut

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5452题目大意: 给你一个图G,图中包含一颗生成树.要求只能删除生成树内的一条边,使得图不联通.问最小的删除 ...

  5. 【转】Javabyte[]数组和十六进制String之间的转换Util------包含案例和代码

    原文网址:http://blog.csdn.net/caijunjun1006/article/details/11740223 Java中byte用二进制表示占用8位,而我们知道16进制的每个字符需 ...

  6. Binary Tree Zigzag Level Order Traversal——LeetCode

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  7. poj 1236强连通图缩点

    题目链接:http://poj.org/problem?id=1236 #include <cstdio> #include <cmath> #include <algo ...

  8. 60秒找到最对的size?为服饰电商提供尺寸匹配解决方案的True Fit获1500万美元融资 | 36氪

    60秒找到最对的size?为服饰电商提供尺寸匹配解决方案的True Fit获1500万美元融资 | 36氪 60秒找到最对的size?为服饰电商提供尺寸匹配解决方案的True Fit获1500万美元融 ...

  9. Postman interceptor

    安装 下载地址: Postman Interceptor Chrome插件下载 1. 下载的是一个crx文件. 2. 在谷歌中打开: chrome://extensions/ 3. 拖动cfx文件到 ...

  10. E - Currency Exchange

    题目大意: 汇率问题,有N个银行,他们之间有一些汇率,某个人手里面拿着其中一种钱,然后在这里面兑换钱币,当然兑换是有汇率和手续费的,然后经过一系列兑换后问手里面的钱是不是能增加? ;; i<le ...