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);
}
}

最新文章

  1. 数据的平面拟合 Plane Fitting
  2. Python 各进制间的转换(转)
  3. iOS8以后自动计算cell的高度
  4. Android 百度云媒体 等播放器播放4:3等多种比例的视频 大小配置的问题
  5. hadoop: hbase1.0.1.1 伪分布安装
  6. asp.net 网站访问变慢
  7. Android属性动画完全解析(中)
  8. [Effective Java]第十章 并发
  9. servlet的配置和上下文
  10. (转)oracle字符集与汉字
  11. CSS中Position属性
  12. android在广播接收器BroadcastReceiver里面再进行发送广播,造成当前广播接收器不断循环执行问题
  13. [命令行] curl查询公网出口IP
  14. django源码分析 LazySetting对象
  15. idea 设置某项目路径下的文件在点击浏览器预览时的前缀
  16. Django(ORM查询联系题)
  17. IIS Web服务扩展中没有Asp.net 2.0
  18. 〖Android〗dropbear一些操作命令备忘
  19. tf.unstack()、tf.stack()
  20. springboot-25-springboot 集成 ActiveMq

热门文章

  1. ORIGIN(起源属性)路由起源骗术
  2. scala安装教程及简单配置
  3. Pycharm连接Mysql失败. [08001] Could not create connection to database server.
  4. Springboot Bean循环依赖问题
  5. JS确认取消按钮使用
  6. P 1024 科学计数法
  7. 【LeetCode】分发糖果
  8. Day2-T3
  9. mui 横屏 竖屏
  10. Information:java: Errors occurred while compiling module 错误