所用知识 数组、双指针、循环遍历 所用语言 Java 解题思路 由于牛位置是升序排列,可以直接遍历,使用num进行计数,count相当于慢指针。 当同一个位置的牛数量小于三时,数组对应位置值不变;当大于三时,慢指针不移动,等待添加下一个牛群中牛的位置。相当于跳过一个牛群中多余的牛的统计。 完整代码 public int remove_duplicates_v3 (int[] nums) { // write code here if (nums.length == 0) { return 0; } int count = 1; int num = 1; for (int i = 1; i &l...