【Leetcode】【Easy】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.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if (!head)
return head; ListNode *p = head; while(p->next) {
if (p->val == p->next->val) {
p->next = p->next->next;
} else {
p = p->next;
}
} return head;
}
};
附录:
C++链表,申请和消除内存
【Leetcode】【Easy】Remove Duplicates from Sorted List的更多相关文章
- 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 ...
- C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array
26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...
- LeetCode Array Easy 26.Remove Duplicates from Sorted Array 解答及疑惑
Description Given a sorted array nums, remove the duplicates in-place such that each element appear ...
- leetcode修炼之路——83. Remove Duplicates from Sorted List
哈哈,我又来了.昨天发现题目太简单就没有放上来,今天来了一道有序链表的题.题目如下: Given a sorted linked list, delete all duplicates such th ...
- LeetCode--LinkedList--83.Remove Duplicates from Sorted List(Easy)
题目地址https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 83. Remove Duplicates from Sor ...
- 83. Remove Duplicates from Sorted List【easy】
83. Remove Duplicates from Sorted List[easy] Given a sorted linked list, delete all duplicates such ...
- 【一天一道LeetCode】#83. Remove Duplicates from Sorted List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...
- 26. Remove Duplicates from Sorted Array【easy】
26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...
- 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...
随机推荐
- Feel Good(两遍单调栈维护区间+前缀和)
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...
- 在linux服务器上配置anaconda和Tensorflow,并运行
1. 查看服务器上的Python安装路径: whereis python 2. 查看安装的Python版本号: python 3. 安装Anaconda: 1)下载 Anaconda2-4.0.0-L ...
- HDU - 4291 循环节
还有这种操作? #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=j;i<=k;i++) #define p ...
- 给新人看的 JavaScript的继承
//这个继承方式是给新人看的,逻辑简单一些 Object.extend=function(props){ //继承父类 var prototype=Object.create(this.prototy ...
- mutillidae之注册页面的Insert型报错注入
http://127.0.0.1/mutillidae/index.php?page=register.php 1.注册一个用户试一试,发现页面只提示用户注册成功信息,并五其它可回显信息,果断尝试盲注 ...
- datagrip 导出数据库备份到本地
1.建立自己的数据库 2.如图 3,结果
- PDFJs 在线预览插件
0.A.到官网 https://mozilla.github.io/pdf.js/getting_started/#download 下载最新版本B 部署到IIS 中访问 pdf.js/web/vie ...
- 使用 PuTTY 时遇到错误:“expected key exchange group packet from server”
情况 使用 PuTTY 通过 SSH 访问 ProxySG 或 Advanced Secure Gateway (ASG) 时,您会看到如下错误:"expected key exchange ...
- MVC Control 接收post请求的json数据
[HttpPost] public string QueryInvoice() { string stream; using (var sr = new StreamReader(Request.In ...
- lxc 容器基础配置篇
一, 首先配置lxc需要的网卡断 吧eth0复制一份变为br0 配置br0 配置eth0 重启网卡 /etc/init.d/network restart 安装lxc软件 需要epel源--- y ...