Remove Duplicates from Sorted Array II
来源:互联网 发布:sql plus是什么 编辑:程序博客网 时间:2024/05/16 01:50
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.length<=2){
return A.length;
}else{
int count =1;
int num=1;
int val=A[0];
for(int i=1;i<A.length;i++){
if(A[i]==val){
if(count<2){
count++;
A[num++]=val;
}
}else{
val=A[i];
A[num++]=val;
count=1;
}
}
return num;
}
}
}
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove duplicates from sorted array II
- Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array II
- LeetCode-Remove Duplicates from Sorted Array II
- Jquery ajax乱码问题
- java类型转换大集合
- 希尔排序shell sort
- 《学习opencv》笔记——关于一些绘图的函数
- java 静态方法和实例方法的区别
- Remove Duplicates from Sorted Array II
- 《学习opencv》笔记——关于一些绘图的函数
- UNIMODAL PALINDROMIC DECOMPOSITIONS——动态规划
- 大二小结
- Rails 入门笔记
- 碎碎念,浅浅饮-------Day30
- JSP的内置对象
- 大二下的期末规划
- spring IOC