[Algo] 117. Array Deduplication III
2024-09-01 11:08:01
Given a sorted integer array, remove duplicate elements. For each group of elements with the same value do not keep any of them. Do this in-place, using the left side of the original array and and maintain the relative order of the elements of the array. Return the array after deduplication.
Assumptions
- The given array is not null
Examples
{1, 2, 2, 3, 3, 3} → {1}
public class Solution {
public int[] dedup(int[] array) {
// Write your solution here.
int slow = 0;
int begin = 0;
int i = 0;
while(i < array.length) {
begin = i;
while (i < array.length && array[begin] == array[i]) {
i += 1;
}
if (i - begin == 1) {
array[slow++] = array[begin];
}
}
return Arrays.copyOf(array, slow);
}
}
最新文章
- 数据的平面拟合 Plane Fitting
- Python 各进制间的转换(转)
- iOS8以后自动计算cell的高度
- Android 百度云媒体 等播放器播放4:3等多种比例的视频 大小配置的问题
- hadoop: hbase1.0.1.1 伪分布安装
- asp.net 网站访问变慢
- Android属性动画完全解析(中)
- [Effective Java]第十章 并发
- servlet的配置和上下文
- (转)oracle字符集与汉字
- CSS中Position属性
- android在广播接收器BroadcastReceiver里面再进行发送广播,造成当前广播接收器不断循环执行问题
- [命令行] curl查询公网出口IP
- django源码分析 LazySetting对象
- idea 设置某项目路径下的文件在点击浏览器预览时的前缀
- Django(ORM查询联系题)
- IIS Web服务扩展中没有Asp.net 2.0
- 〖Android〗dropbear一些操作命令备忘
- tf.unstack()、tf.stack()
- springboot-25-springboot 集成 ActiveMq