Leetcode Remove Duplicates from Sorted Array
2013-10-15 22:22
288 查看
数组删除重复元素,要求常数的空间复杂度。比较简单。
class Solution { public: int removeDuplicates(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. if(n == 0 || n == 1) return n; int tmp = A[0], pos = 1, cnt = n; for(int i = 1; i < n; i++){ if(tmp == A[i]){ cnt--; } else{ A[pos] = tmp = A[i]; pos++; } } return cnt; } };
相关文章推荐
- [leetcode题后感] Remove Duplicates from Sorted Array I、 II
- 【leetcode】Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array
- LeetCode 26 Remove Duplicates from Sorted Array(从已排序数组中移除重复元素)
- LeetCode刷题笔录 Remove Duplicates From Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array@python
- 【leetcode 数组】Remove Duplicates from Sorted Arrayd
- 【Leetcode】Remove Duplicates from Sorted Array II (Removing)
- 【LeetCode-26】 Remove Duplicates from Sorted Array(C++)
- leetcode note--leetcode 26 Remove Duplicates from Sorted Array
- leetcode[80]:Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- leetcode[80]Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array 解题报告
- LeetCode Remove Duplicates from Sorted Array
- leetcode: Remove Duplicates from Sorted Array
- 【LeetCode with Python】Remove Duplicates from Sorted Array II
- Leetcode 线性表 Remove Duplicates from Sorted Array
- leetcode26. [Array]Remove Duplicates from Sorted Array
- 【Leetcode】Remove Duplicates from Sorted Array