[LeetCode]Remove Duplicates from Sorted Array
2014-05-21 20:55
267 查看
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) { int i, j; for (i = j = 1; i < n; i++) { if (A[i] != A[i - 1]) { A[j++] = A[i]; } } return n ? j : 0; } };
相关文章推荐
- LeetCode Remove Duplicates from Sorted Array II
- leetcode 日经贴,python code -Remove Duplicates from Sorted Array
- 【leetcode】26. Remove Duplicates from Sorted Array
- 【leetcode】Remove Duplicates from Sorted Array 1和2
- [LeetCode]26. Remove Duplicates from Sorted Array
- LeetCode Remove Duplicates from Sorted Array
- LeetCode_Remove Duplicates from Sorted Array
- leetcode-26-Remove Duplicates from Sorted Array 顺序表
- [LeetCode]80 Remove Duplicates from Sorted Array II
- 【Leetcode】Remove Duplicates from Sorted Array II
- [LeetCode]26. Remove Duplicates from Sorted Array
- leetcode 26 Remove Duplicates from Sorted Array
- Leetcode Remove Duplicates from Sorted Array II
- LeetCode 26--- Remove Duplicates from Sorted Array
- LeetCode - Remove Duplicates from Sorted Array
- 【LeetCode】-Remove Duplicates from Sorted Array II
- [leetcode26] Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array leetcode java
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
- LeetCode之Remove Duplicates from Sorted Array