26. Remove Duplicates from Sorted Array
来源:互联网 发布:百度地图编辑软件 编辑:程序博客网 时间:2024/06/05 03:05
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.
双指针遍历。
int removeDuplicates(vector<int>& nums) { int i = 0; for( int j=1; j<nums.size(); j++ ) { if( nums[j] != nums[j-1]) nums[++i] = nums[j]; } return nums.empty() ? 0 : i+1;}
0 0
- [LeetCode]26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode --- 26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- [Leetcode] 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 【leetcode】26. Remove Duplicates from Sorted Array
- 【leetcode】 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- [leetCode]26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- CodeForces - 686B
- 【杭电oj】5246 - 超级赛亚ACMer(二分 & 贪心 & STL)
- Android学习第3天,test、sqlite、listview、dialog
- 华为机试---学英语
- Java读写二进制文件操作
- 26. Remove Duplicates from Sorted Array
- 入夜。
- 文件上传之servlet3.0实现
- linux内核数据结构之kfifo
- C++中的三大缺省函数 之 《深拷贝与浅拷贝》
- css布局之负外边距的妙用
- Android BaseAdapter的极简封装
- play_java框架学习01
- 有关数据备份、存储全路径、备份设备的一些知识点(文件级备份、块备份)整理