Remove Duplicates from Sorted Array II - LeetCode
来源:互联网 发布:成捷迅概预算软件价格 编辑:程序博客网 时间:2024/06/01 10:22
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]
.
下面是一个不需要用Hash的简单作法,重点是要在原数据集上修改:
public class Solution { public int removeDuplicates(int[] A) { if (A == null || A.length == 0) { return 0; } int size = 0; for (int i = 1; i < A.length; i++) { if (A[i] == A[size] && size > 0 && A[size-1] == A[size]) { continue; } A[++size] = A[i]; } return size + 1; }}
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
- 1033. To Fill or Not to Fill (25)
- zend framework框架的action大小写和请求url大小写问题
- Html中td自动换行问题
- svn url does not contain valid patch
- 什么叫别让孩子输在起跑线上?! - 电子产品已成儿童“多动症”诱因
- Remove Duplicates from Sorted Array II - LeetCode
- 行业应用也在不断诞生
- Quartz使用 在程序中启停定时器
- Java Stream Closed异常
- C#统计文章中单词的重复次数,并且按照次数从高到低排序返回(无法处理中文)
- Android_HttpClient
- UVALive 3211 Now or later(二份答案+2-SAT)
- 怎么样将mac中的pdf倒入ipad中,方便我们查看
- Jos - lab1 Boot the PC