Remove Duplicates from Sorted Array
来源:互联网 发布:电脑淘宝店招尺寸 编辑:程序博客网 时间:2024/06/07 15:47
Q:
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 A = [1,1,2]
,
Your function should return length = 2
, and A is now [1,2]
.
Solution:
public class Solution { public int removeDuplicates(int[] A) { if (A.length == 0) return 0; int j = 1; for (int i = 1; i < A.length; i++) { if (A[i-1] != A[i]) { A[j] = A[i]; j++; } } if (j < A.length) A[j] = '\0'; return j; }}
0 0
- 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
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- 多线程中使用COM组件时的初始化问题
- iOS Block的语法
- POJ 2155 Matrix 二维树状数组
- SQL优化----dbms_sqltune详解
- cookie的技术实现
- Remove Duplicates from Sorted Array
- setContentView和inflate区别
- Berkeley套接字
- 用viso画C++类图
- 第10题 Linked List Cycle II
- ios swift学习日记2-基础部分
- Codeforces 474E Pillars dp+线段树(水
- php获取远程图片体积大小的实例
- Android---UI篇---DatePicker,TimePicker(日期和时间)