LeetCode题解:Remove Duplicates from Sorted List
来源:互联网 发布:淘宝相似图片搜索 编辑:程序博客网 时间:2024/06/01 08:44
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.
题意:给定一个有序脸变,删除重复出现的元素使得所有元素只出现一次
解决思路:遇到相同元素向下,不同再改变指针
代码:
public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head==null || head.next==null) return head; ListNode p = head; ListNode curr = p.next; while(curr!=null) { if(curr.val!=p.val) { p.next=curr; p=curr; } curr=curr.next; } p.next=curr; return head; }}
0 0
- LeetCode题解:Remove Duplicates from Sorted List
- LeetCode题解:Remove Duplicates from Sorted List
- LeetCode题解:Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List ---Leetcode 我的java题解
- LeetCode 题解(160): Remove Duplicates from Sorted List II
- LeetCode 题解(225) : Remove Duplicates from Sorted List
- LeetCode题解-83-Remove Duplicates from Sorted List
- Leetcode题解 83. Remove Duplicates from Sorted List
- LeetCode题解-82-Remove Duplicates from Sorted List II
- leetcode题解-83. Remove Duplicates from Sorted List
- leetcode题解-83. Remove Duplicates from Sorted List
- leetcode题解-82. Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- LeetCode题解:Remove Duplicates from Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array题解
- 使用Thrift RPC编写程序
- Jedis使用总结【pipeline】【分布式的id生成器】【分布式锁【watch】【multi】】【redis分布式】
- 最新关于try ,catch,throw的使用小结
- 【SDOI2009】【BZOJ1875】HH去散步
- 题目1841 Find the Shortest Common Superstring(KMP)
- LeetCode题解:Remove Duplicates from Sorted List
- Codeforces 558E. A Simple Task (线段树+计数排序)
- OGG-01705 input trail file './dirdat/fc075295' is greater than the size of the file
- 从零开始学Java之出入门卫管理(二)
- C# 接口的隐式与显示实现
- C#(winform)新建项目后,调试异常终止且无错误提示问题解决办法
- hdu1166-敌兵布阵(线段树)
- hdu5047 Sawtooth(推导+java大数)
- Spring MVC入门案例(2)