leetcode_Remove Duplicates from Sorted Array II
来源:互联网 发布:php zrem 编辑:程序博客网 时间:2024/04/30 15:52
描述:
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array nums = [1,1,1,2,2,3]
,
Your function should return length = 5
, with the first five elements of nums being 1
, 1
, 2
, 2
and 3
. It doesn't matter what you leave beyond the new length.
思路:
直接略过重复元素
代码:
public int removeDuplicates(int[] A) { if(A==null) return 0; if(A.length<3) return A.length; int len=A.length; int index=2;//new length int i=2;//to traverse the array int temp=0; while(i<len) { temp=index-2; while(i<len&&A[i]==A[temp]) i++; if(i<len) A[index++]=A[i]; i++; } return index; }
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
- LeetCode_Remove Duplicates from Sorted Array
- leetcode_Remove Duplicates from Sorted Array
- LeetCode_Remove Duplicates from Sorted Array
- LeetCode_remove-duplicates-from-sorted-array
- LeetCode_Remove Duplicates from Sorted Array
- Leetcode_remove-duplicates-from-sorted-array-ii (c++ and python version)
- Leetcode_remove-duplicates-from-sorted-list-ii
- LeetCode_Remove Duplicates from Sorted List II
- LeetCode_Remove Duplicates from Sorted List
- LeetCode_remove-duplicates-from-sorted-list
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- uva 10397 Connect the Campus kruskal 算法变形
- python(5) dict 特点
- Microsoft SQL Server,错误: 51
- Loaders 异步加载数据(一)
- 黑马程序员---java继承详解
- leetcode_Remove Duplicates from Sorted Array II
- UIView的两种动画
- 【Android】系统Root与静默安装
- python(6) 更新dict
- 第11周 程序阅读——继承和派生 自选阅读(2)
- Android中接口回调——fagment与activity
- UITableView刷新指定的row或者section
- 1、Java SE入门、jdk及第一个java程序
- 字符串输出某列