Remove Duplicates from Sorted Array II
来源:互联网 发布:12345数字打字软件 编辑:程序博客网 时间:2024/06/08 18: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 { /** * @param A: a array of integers * @return : return an integer */ public int removeDuplicates(int[] nums) { // write your code here if (nums==null) return -1; if(nums.length<=2)return nums.length; int newIndex=1; for (int i=2;i<nums.length ;i++ ) { if (nums[i]!=nums[newIndex]||nums[i]!=nums[newIndex-1]) { newIndex++; nums[newIndex]=nums[i]; } } return newIndex+1; }}
0 0
- 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
- Android 自定义控件
- php+mysql
- 【Educational Codeforces Round 2C】【贪心】最少修改数下得到字典序尽可能小回文串
- openstack之neutron代码分析---(1)neutron初始化流程
- 转载:linux 内存管理——内核的shmall 和shmmax 参数
- Remove Duplicates from Sorted Array II
- 今天来打打java大数模板(整型)
- Android UICC 好文关键字备忘
- 【C语言提高01】冒泡排序和数组做参数的问题
- 面向对象设计的原则
- mysql 存储长文本
- 从结构体角度浅谈C语言的数据类型和变量
- 一位90后女生的IT之旅
- 对链式队列结构实现的探讨