LeetCode: Remove Duplicates from Sorted Array
2014-09-25 08:43
190 查看
题目
https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/分析
从前向后遍历, 如果该元素不和前面元素重复, 就该元素排到前面。代码
class Solution{
public:
int removeDuplicates(int A[], int n)
{
if (n < 1)
return n;
int count = 1;
for (int i = 1; i < n; i++)
if (A[i] != A[i-1])
A[count++] = A[i];
return count;
}
};
参考
http://blog.csdn.net/xudli/article/details/8423225相关文章推荐
- [leetcode]_Remove Duplicates from Sorted Array II
- leetcode Remove Duplicates from Sorted Array
- leetcode 26 Remove Duplicates from Sorted Array C++
- [Leetcode] Remove Duplicates from Sorted Array
- [Leetcode 26, easy] Remove Duplicates from Sorted Array
- leetcode -- 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 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