LeetCode Remove Duplicates from Sorted Array
2015-02-15 23:25
344 查看
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 A =
Your function should return length =
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array A =
[1,1,2],
Your function should return length =
2, and A is now
[1,2].
class Solution { public: int removeDuplicates(int A[], int n) { if(n==0)return 0; int index=0; for(int i=1;i<n;++i){ if(A[i]!=A[index]) A[++index]=A[i]; } return index+1; } };
相关文章推荐
- 【Leetcode】【Easy】Remove Duplicates from Sorted Array
- 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
- leetcode_question_26 Remove Duplicates from Sorted Array
- LeetCode 26 Remove Duplicates from Sorted Array(从已排序数组中移除重复元素)
- [leetcode]26. Remove Duplicates from Sorted Array(java)
- Leetcode_c++: Remove Duplicates from Sorted Array II (080)
- (leetcode) Remove Duplicates from Sorted Array II
- LeetCode(26)Remove Duplicates From Sorted Array
- [leetcode] 26. Remove Duplicates from Sorted Array 解题报告
- LeetCode – Refresh – Remove Duplicates from Sorted Array II
- Leetcode: Remove Duplicates from Sorted Array II
- LeetCode 26 Remove Duplicates from Sorted Array
- LeetcodeArray283 MoveZero +LeetcodeArrary26 Remove Duplicates from Sorted Array
- LeetCode80——Remove Duplicates from Sorted Array II
- Leetcode: 26. Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array II--LeetCode
- LeetCode解题思路之Remove Duplicates from Sorted Array