[Lintcode]Remove Duplicates from Sorted Array
来源:互联网 发布:电视连接网络 编辑:程序博客网 时间:2024/06/03 18:56
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.
Example
Given input array A = [1,1,2]
,
Your function should return length = 2
, and A is now [1,2]
.
public class Solution { /** * @param A: a array of integers * @return : return an integer */ public int removeDuplicates(int[] nums) { if(nums.length == 0) return 0; int index = 0; for(int i = index + 1; i < nums.length; i++) { if(nums[index] != nums[i]) { nums[index + 1] = nums[i]; index++; } } return index + 1; }}
0 0
- [Lintcode]Remove Duplicates from Sorted Array
- [Lintcode] Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates From Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Android事件分发机制以及滑动冲突处理
- 惭愧吧!!!
- MySQL存储引擎--MyISAM与InnoDB区别
- 从现有仓库克隆并开发项目
- 【JAVA】19、多维数组
- [Lintcode]Remove Duplicates from Sorted Array
- 经典的Java基础面试题集锦汇总
- javascript数组 添加元素
- UEditor 报错:Uncaught ReferenceError: UE is not defined; Uncaught ReferenceError: UM is not defined
- 作为程序员在公司不要与和同事说的几个要点
- HttpClient 教程 (一)
- HDU 2295 Radar(二分+重复覆盖)
- 使用导航控制器的笔记
- D2