【leetcode】Remove Duplecates from Sorted Array 和 Remove Duplicates from Sorted List
来源:互联网 发布:苏联大清洗知乎 编辑:程序博客网 时间:2024/06/08 07:28
1、Remove Duplecates from Sorted Array
题目要求:
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array nums = [1,1,2]
,
Your function should return length = 2
, with the first two elements of nums being 1
and 2
respectively. It doesn't matter what you leave beyond the new length.
解题思路:题目中要求不能分配额外的数组空间,因此,我们只能借助原来的数组删除重复的元素,
代码如下:
2、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
.
解题思路:将后一个节点值与前一个节点值进行比较,如果相等,则删除
代码如下:
- 【leetcode】Remove Duplecates from Sorted Array 和 Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List :from LeetCode
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】Remove Duplicates from Sorted Array
- 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 II
- [Leetcode] Remove Duplicates from Sorted Array
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- leetcode 35: Remove Duplicates from Sorted Array
- [LeetCode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array
- Leetcode: Remove Duplicates from Sorted Array
- linux下的"BusHound"——usb_mon非常好
- c语言中二位动态数组
- 技术实现(2)之数据库备份恢复的设计与实现
- QT常用快捷键
- oj期中测验--B: 刑警的射击成绩(2449)
- 【leetcode】Remove Duplecates from Sorted Array 和 Remove Duplicates from Sorted List
- 左手有话说(2)
- 【Linux多线程同步】读写锁
- JQUERY EASYUI DATAGRID设置可编辑行的某个列不可编辑
- Linux-gdb调试
- 观察者模式
- CSS清除浮动的方法优缺点分析
- ORACLE PROFILE(配置文件)查询
- PhoneGAP实现带进度条的文件上传(支持任意类型文件)