Leetcode之四Remove Duplicates from Sorted Array II
来源:互联网 发布:智慧芽数据库 编辑:程序博客网 时间:2024/06/11 21:50
copyright:leetcode
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]
.
import java.util.ArrayList;public class Solution {public Solution(){System.out.println(removeDuplicates(new int[]{1, 1}));} public int removeDuplicates(int[] A) {if(A.length == 0)return 0;ArrayList<Integer> list = new ArrayList<Integer>();list.add(A[0]);int counter = 1;for(int i=1;i < A.length;i++){if(list.get(list.size() - 1) != A[i]){counter = 1;list.add(A[i]);}else if(counter < 2 ){counter++;list.add(A[i]);}}System.out.print("[");for(int i=0;i < list.size() - 1;i++)System.out.print(list.get(i)+",");//System.out.println(list.get(list.size() - 1)+"]");//return list.size(); }public static void main(String[] args){new Solution();}}
以上代码在jdk1.6上运行结果正确,提交时通不过,显示
而我的运行结果是正确的,不知为么:
有人遇到相同问题吗???
0 0
- 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
- [LeetCode] Remove Duplicates from Sorted Array II
- Linux文件系统
- 解决安装win7后ubuntu无法启动问题
- hdu 1875 畅通工程再续
- http://tgyd2006.iteye.com/blog/871048
- 4.将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- Leetcode之四Remove Duplicates from Sorted Array II
- Towers codeforce +dp
- 北斗卫星导航系统BCH解码的实现结构
- 7.,一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同
- NS-3安装过程
- 简易播放器
- codeforces229D. Towers
- POJ3624 Charm Bracelet 【01背包】
- Linux系统中如何添加、使用硬盘