LeetCode 80 Remove Duplicates from Sorted Array II
来源:互联网 发布:2016年淘宝卖家数量 编辑:程序博客网 时间:2024/05/19 03:20
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]
.
public class Solution { public int removeDuplicates(int[] A) { if(A==null || A.length<1) return 0; int i=1; int elem=A[0]; int counter=1; for(int j=1; j<A.length; j++) { if(A[j]!=elem) { elem=A[j]; A[i++] = A[j]; counter=1; }else{ counter++; if(counter==2) A[i++]=A[j]; } } return i; }}
0 0
- LeetCode-Array-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
- [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
- 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
- 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
- [LeetCode] Remove Duplicates from Sorted Array II
- Dreamhost 提示No input file specified. 的解决办法
- 从Java到C++——union的用法
- 一些数组的算法题
- Binary Tree Preorder Traversal -先序遍历
- spoj7258 Lexicographical Substring Search(SUBLEX) 后缀自动机
- LeetCode 80 Remove Duplicates from Sorted Array II
- if-elif-else使用
- 实际工作中,Eclipse常用的快捷键
- Linux Shell常用技巧
- css常用布局方式和技巧
- 【男士必须收藏】男士健身方法
- 由矩阵元素的下标值i,j求矩阵元素
- CTime类
- Java线程:概念与原理