【Leetcode】Remove Duplicates from Sorted Array
  iVhBmnbWORLX 2023年11月02日 116 0
i++


题目链接:https://leetcode.com/problems/remove-duplicates-from-sorted-array/

题目:

once

Do not allocate extra space for another array, you must do this in place with constant memory.

For example,

Given input array nums = [1,1,2],2, with the first two elements of nums being 1 and 2

思路:

思路跟 一样。

算法:

public int removeDuplicates(int[] nums) {
		int count = 0;
		for (int i = 1; i < nums.length; i++) {
			if (nums[i] == nums[i -1]) {
				count++;
			}
			nums[i - count] = nums[i];
		}
		return nums.length - count;
	}




【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  gBkHYLY8jvYd   2023年12月06日   48   0   0 #includecii++
  gBkHYLY8jvYd   2023年12月09日   29   0   0 cii++数据
  gBkHYLY8jvYd   2023年12月06日   23   0   0 cii++依赖关系
  gBkHYLY8jvYd   2023年11月19日   20   0   0 #includei++数据
  lh6O4DgR0ZQ8   2023年11月24日   17   0   0 cii++c++
  gBkHYLY8jvYd   2023年11月19日   21   0   0 i++测试数据数据
  gBkHYLY8jvYd   2023年11月22日   22   0   0 ioscii++
  gBkHYLY8jvYd   2023年12月10日   22   0   0 #include数组i++
  gBkHYLY8jvYd   2023年12月08日   20   0   0 #includecii++
  pv5yotLONGGI   2023年11月02日   41   0   0 Systemmathi++
  ezcY5UZFiUJ6   2023年11月02日   57   0   0 i++随机数最小值
  gBkHYLY8jvYd   2023年11月14日   28   0   0 #includei++升序
  kIM7GUNpnV3x   2023年11月02日   59   0   0 数组Systemi++
iVhBmnbWORLX