LeetCode: 26. Remove Duplicates from Sorted Array
来源:互联网 发布:hbase删除数据 编辑:程序博客网 时间:2024/06/06 08:33
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
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],
Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn’t matter what you leave beyond the new length.
Solution
public class RemoveDuplicatesfromSortedArray { public int removeDuplicates(int[] nums) { if (nums.length == 0) return 0; int j = 0; for (int i = 0; i < nums.length; i++) { if (nums[i] != nums[j]) nums[++j] = nums[i]; } return ++j; }}
关键在于题目还要求对Nums进行去重复。所以不仅仅是统计不重复数的问题,还要把数据去重复。
阅读全文
0 0
- [LeetCode]26.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] 26. 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 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 【LeetCode】26. 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 26. Remove Duplicates from Sorted Array
- LeetCode - 26. Remove Duplicates from Sorted Array
- leetcode-26. Remove Duplicates from Sorted Array
- 26.[Leetcode]Remove Duplicates from Sorted Array
- 实用支持移动、PC端的textarea内容复制粘贴小插件
- ASP 标题多字符超出改为...
- sql报错:查询块具有不正确的结果列数
- CLR via C# 阅读笔记1
- 最小生成树-Prim算法和Kruskal算法
- LeetCode: 26. Remove Duplicates from Sorted Array
- 数据库分区(2017-8-7)
- c/c++多级指针与“多维”数组
- RHEL Linux6.5系统配置本地yum源的几种方式
- C#中实现动态隐藏/显示RDLC报表的表头(列)
- (8)Math对象、Global对象(进制转换)
- 如何用Java和jsp获取服务器ip
- linux找不到动态链接库 .so文件的解决方法
- oracle闪回功能详解(oracle独有的flashback功能)