Leetcode 82
有个错误就是member access within null pointer of type 'struct ListNode'
其实就是判断了指针是否异常了,比如NULL->next之类。要记得用new给节点初始化,而指针不需要初始化
/**
* 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 == NULL) return head;
ListNode* bighead = new ListNode();
ListNode* pre;
ListNode* move; bighead->next = head;
pre = bighead;
move = head; while(move != NULL && move->next != NULL){
if(move->next->val == move->val){
while((move->next != NULL) && (move->next->val == move->val)){
move = move->next;
}
pre->next = move->next;
move = move->next;
}
else{
pre = pre->next;
move = move->next;
}
}
return bighead->next;
}
};
Leetcode 82的更多相关文章
- [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- LeetCode 82. 删除排序链表中的重复元素 II(Remove Duplicates from Sorted List II)
82. 删除排序链表中的重复元素 II 82. Remove Duplicates from Sorted List II 题目描述 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中没有 ...
- LeetCode 82,考察你的基本功,在有序链表中删除重复元素II
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题的第51篇文章,我们来看LeetCode第82题,删除有序链表中的重复元素II(Remove Duplicates ...
- [LeetCode] 82. Remove Duplicates from Sorted List II_Medium tag: Linked List
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinctnumbe ...
- LeetCode(82)题解: Remove Duplicates from Sorted List II
https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 题目: Given a sorted linked list, ...
- [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项 II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- Java实现 LeetCode 82 删除排序链表中的重复元素 II(二)
82. 删除排序链表中的重复元素 II 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 示例 1: 输入: 1->2->3->3->4- ...
- leetcode 82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode#82]Remove Duplicates from Sorted Array II
Problem: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? F ...
随机推荐
- Vlock用于有多个用户访问控制台的共享 Linux 系统
当你在共享的系统上工作时,你可能不希望其他用户偷窥你的控制台中看你在做什么.如果是这样,我知道有个简单的技巧来锁定自己的会话,同时仍然允许其他用户在其他虚拟控制台上使用该系统. 要感谢Vlock(Vi ...
- Web前端学习笔记之安装和使用PhantomJS
0x00 安装PhantomJS(linux环境安装) 将PhantomJS下载在/usr/local/src/packet/目录下(这个看个人喜好) 操作系统:CentOS 7 64-bit 1.下 ...
- Win32 实现 MFC CFileDialog 对话框
void CWriteWnd::OpenFileDialog() { OPENFILENAME ofn; TCHAR szFile[MAX_PATH] = _T(""); Zero ...
- 本地连接VM virtualBox ubuntu16.04 中的Mysql数据库
1.打开mysql配置文件vim /etc/mysql/mysql.conf.d/mysqld.cnf 将bind-address = 127.0.0.1注销 2.重启ubuntu数据库 3. ...
- python_paramiko_SSHException Invalid requirement, parse error at
不加sleep(0.5)会出现SSHException: Invalid requirement, parse error at " '' "问题,原因暂时未知. 结论如下 如果不 ...
- SRLTE,SGLTE,SVLTE,CSFB,VoLTE的区别【转】
本文转载自:https://blog.csdn.net/dangbochang/article/details/43851979 SRLTE——Single Radio LTE,俗称单待LTE. SG ...
- Linux内存管理--虚拟地址、逻辑地址、线性地址和物理地址的区别(二)【转】
本文转载自:http://blog.csdn.net/yusiguyuan/article/details/9668363 这篇文章中介绍了四个名词的概念,下面针对四个地址的转换进行分析 CPU将一个 ...
- 如果恨一个程序员,忽悠他去做iOS开发
如果你恨一个程序员,忽悠他去做iOS开发.不管他背景是cobel还是 java,送他一本iOS开发的书.这种书最好是国人写的,容易以偏概全一点,相比洋鬼子的书,更容易学到皮毛.这叫舍不得孩子套不着狼, ...
- 【第四章】 springboot + swagger
注:本文参考自 http://www.jianshu.com/p/0465a2b837d2 swagger用于定义API文档. 好处: 前后端分离开发 API文档非常明确 测试的时候不需要再使用URL ...
- js中this关键字的使用
<script> //题目一:理解r1与r2的输出 function addFactory(){ var adder = 5; return function(data){ adder + ...