leetcode 26 80 删除已排序数组中重复的数据
2017-03-29 08:58
405 查看
80. Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array nums =
Your function should return length =
修改repeat可以实现任意重复次数
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,
2and
3. It doesn't matter what you leave beyond the new length.
public static int removeDuplicatesMyself(int[] nums) { if (nums.length < 2) return nums.length; final int count = nums.length; int repeat = 2; int occor = 0; int index = 0; for (int i = 0; i < count; ++i) { if (occor < repeat) nums[index++] = nums[i]; if (i < count - 1 && nums[i] == nums[i + 1]) { occor++; } else { occor = 0; } } return index; }
修改repeat可以实现任意重复次数
相关文章推荐
- Leetcode-26-从排序数组中删除重复项
- 删除已排序数组中的重复数据
- LeetCode 26. 从排序数组中删除重复项
- LeetCode: Remove Duplicates from Sorted Array II(在排序数组中删除重复元素)
- 【Leetcode】从排序数组中删除重复元素
- [LeetCode] 2018.3.22-从排序数组中删除重复项
- leetCode 80.Remove Duplicates from Sorted Array II (删除排序数组中的重复II) 解题思路和方法
- leetCode 26.Remove Duplicates from Sorted Array(删除数组重复点) 解题思路和方法
- leetcode:26&80 Remove Duplicates from Sorted Array 删除数组中的重复元素
- leetcode_26. Remove Duplicates from Sorted Array 在排好序的数组中删除重复的数字,不允许分配其他空间
- LeetCode-26-Remove Duplicates from Sorted Array(消除已排序数组中的重复元素)
- leetcode 26. Remove Duplicates from Sorted Array从排序数组中移出重复元素(双指针)
- [Leetcode] Remove duplicates from sorted array 从已排序的数组中删除重复元素
- LeetCode:从排序数组中删除重复项
- Leetcode26:Remove Duplicates from Sorted Array(移除已排序数组中重复的数字)
- Leetcode 从排序数组中删除重复项
- [Leetcode] Remove duplicates from sorted array ii 从已排序的数组中删除重复元素
- LeetCode 26 Remove Duplicates from Sorted Array(从已排序数组中移除重复元素)
- 【LeetCode-面试算法经典-Java实现】【026-Remove Duplicates from Sorted Array(删除排序数组中的重复元素)】
- LeetCode 26 Remove Duplicates from Sorted Array(从已排序数组中移除重复元素)