[LeetCode] 081: Remove Duplicates from Sorted Array II
2017-09-10 20:51
381 查看
[Problem]
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array A =
Your function should return length =
[Solution]
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array A =
[1,1,1,2,2,3],
Your function should return length =
5, and A is now
[1,1,2,2,3].
[Solution]
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 <= 2)return n; int i = 1, j = 2; while(j < n){ if(!(A[i] == A[j] && A[i-1] == A[j])){ A[++i] = A[j]; } j++; } return i+1; } };说明:版权所有,转载请注明出处。Coder007的博客
相关文章推荐
- LeetCode Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II--LeetCode
- LeetCode: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 II
- LeetCode: Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II (Java)
- LeetCode26/27/80/75 Remove Duplicates from Sorted Array I and II/Remove Element/Set Colors**
- LeetCode Remove Duplicates from Sorted Array II
- leetcode[80]Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- leetcode[80]:Remove Duplicates from Sorted Array II
- LeetCode-80-Remove Duplicates from Sorted Array II(递归)-Medium
- leetcode-80-Remove Duplicates from Sorted Array II 顺序表
- 【LeetCode从零单刷】Remove Duplicates from Sorted Array I & II
- [leetcode] Remove Duplicates from Sorted Array II
- LeetCode之Remove Duplicates from Sorted Array II
- Leetcode Remove Duplicates from Sorted Array II