leetcode题解-83. Remove Duplicates from Sorted List
来源:互联网 发布:linux cern 知乎 编辑:程序博客网 时间:2024/06/14 00:48
题意:给定一个单向已排序的链表,删除链表中重复的元素使每个元素只出现一次。
例子:
1->1->1->2,返回1->2
1->1->2->3->3->,返回1->2->3
思路:两个指针 ,分别从头开始,如果下一指针指向的元素与上一指针指向的元素相同则只将下一指针后移;否则两指针同时后移。
class Solution { public ListNode deleteDuplicates(ListNode head) { if(head == null) return null; ListNode left = head; ListNode right = head.next; while(right != null){ if(right.val == left.val){ right = right.next; }else{ left.next = right; left = right; } } left.next = null; return head; }}
阅读全文
1 0
- LeetCode题解:Remove Duplicates from Sorted List
- LeetCode题解:Remove Duplicates from Sorted List
- Leetcode题解 83. Remove Duplicates from Sorted List
- leetcode题解-83. Remove Duplicates from Sorted List
- leetcode题解-83. Remove Duplicates from Sorted List
- [LeetCode]83.Remove Duplicates from Sorted List
- [Leetcode] 83. Remove Duplicates from Sorted List
- LeetCode --- 83. Remove Duplicates from Sorted List
- [leetcode] 83.Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List LeetCode
- leetcode 83. Remove Duplicates from Sorted List
- [LeetCode]83. Remove Duplicates from Sorted List
- 【LeetCode】83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- [leetcode] 83. Remove Duplicates from Sorted List
- leetcode 83. Remove Duplicates from Sorted List
- java学习笔记
- 网络爬虫基本原理
- python argparse模块
- javaEE基础篇,day0:知识点归纳
- linux克隆
- leetcode题解-83. Remove Duplicates from Sorted List
- Sqlmap初步了解
- LeetCode-023 Merge k Sorted Lists
- 走redis缓存和不走缓存TPS差异明显对比
- 状态机(三):Verilog设计注意问题
- 第二周 Linux基础命令入门(二)
- LeetCode<Day2> Distribute Candies
- the general framework of RL_DQN
- java小细节不然很容易报错或者出逻辑问题得不到自己想要的。