2 Star 0 Fork 0

Mr.Z / bigsai-algorithm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LeetCode 26删除排序数组中的重复项.md 698 Bytes
一键复制 编辑 原始数据 按行查看 历史
张赛 提交于 2020-11-26 10:08 . update

LeetCode 26删除排序数组中的重复项

image-20201117204631926

分析: 这题很简单,用一个index标记当前位置,用i遍历判断是否和前一个相等,如果相等不操作,不相等就重新存入,最后这个index返回即可,当然,虽然是个int类型的函数,但是题目要求存到数组中会判定数组的,需要存一下。

实现代码为:

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

finish!

Java
1
https://gitee.com/sillycoder/bigsai-algorithm.git
git@gitee.com:sillycoder/bigsai-algorithm.git
sillycoder
bigsai-algorithm
bigsai-algorithm
master

搜索帮助