RemoveDuplicatesfromSortedList
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例 1:
输入: 1->1->2
输出: 1->2
示例 2:
输入: 1->1->2->3->3
输出: 1->2->3
思路 :判断当前结点与其下一个结点值是否相等,相等则删除下一个节点
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode* cur = head;
while(cur&&cur->next)
{
if(cur->val == cur->next->val)
{
cur->next = cur->next->next;
}
else
{
cur = cur->next;
}
}
return head;
}
};
RemoveDuplicatesfromSortedList的更多相关文章
- leetcode — remove-duplicates-from-sorted-list
/** * Source : https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ * * * Given a so ...
- remove-duplicates-from-sorted-list (删除)
题意略: 思路:先造一个点它与所有点的值都不同,那么只要后面两个点的值相同就开始判断后面是不是也相同,最后将相同的拆下来就可以了. #include<iostream> #include& ...
- LeetCode——remove-duplicates-from-sorted-list
Question Given a sorted linked list, delete all duplicates such that each element appear only once. ...
- remove-duplicates-from-sorted-list I&II——去除链表中重复项
I.Given a sorted linked list, delete all duplicates such that each element appear only once. For exa ...
- [LeetCode] Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- leetcode算法分类
利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problem ...
- BUG-FREE-For Dream
一直直到bug-free.不能错任何一点. 思路不清晰:刷两天. 做错了,刷一天. 直到bug-free.高亮,标红. 185,OA(YAMAXUN)--- (1) findFirstDuplicat ...
- leetcode bugfree note
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...
- 转载 ACM训练计划
leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode. ...
随机推荐
- this与回调函数
在c++里回调函数分2种: 全局函数:不包函在类的内部 或 类内部的静态函数 类内部函数(或叫 局部函数):需要通过实例化后的对象调用的 因c++是c的一层封装,所以类似c里struct内的函数 在传 ...
- ORA-01882 timezone region not found
解决方案有2个 1.在java运行环境中添加配置,制定时区 -Duser.timezone=GMT 2.修改系统时区 linux 下 1. 查看当前时区 date -R 2. 修改设置时区 方法(1) ...
- linux 统计某目录文件的行数
通过find 正则搜索文件 find . -regex '.*\.c\|.*\.h' 每个文件的行数 find . -regex '.*\.c\|.*\.h' | xargs wc -l 显示文件的总 ...
- 深入理解 RPC
学习资料 https://juejin.im/book/5af56a3c518825426642e004
- MySql cmd下的学习笔记 —— 有关分组的操作(group by)
(一) 把建立的goods表找到 (二) 当cat_id = 3时,计算所有商品的库存量之和 计算每个cat_id下的库存量(group by) 需要用到分组,把每个红框内的计算在一起 筛选出本店价比 ...
- 配置中文分词器 IK-Analyzer-Solr7
先下载solr7版本的ik分词器,下载地址:http://search.maven.org/#search%7Cga%7C1%7Ccom.github.magese分词器GitHub源码地址:http ...
- Spotlight LGWR1 一直告警
http://www.itpub.net/thread-1181372-1-1.html
- openGL之坐标变换
- async_retrying
from async_retrying import retry import aiohttp import asyncio @retry(attempts=6) async def fetch(): ...
- UrlDecode
void Decode(char *p){int i=0;while(*(p+i)){ if ((*p=*(p+i)) == '%') { *p=*(p+i+1) >= 'A' ? ((*(p+ ...