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

[Algo] 117. Array Deduplication III的更多相关文章

  1. [Algo] 118. Array Deduplication IV

    Given an unsorted integer array, remove adjacent duplicate elements repeatedly, from left to right. ...

  2. [Algo] 115. Array Deduplication I

    Given a sorted integer array, remove duplicate elements. For each group of elements with the same va ...

  3. PHP世纪万年历

    <?  //世纪万年历  #这是唯一的设置-请输入php文件的位置  $file="http://192.168.1.168/php/rl/s2m.php";  //#农历每 ...

  4. numpy&pandas补充常用示例

    Numpy [数组切片] In [115]: a = np.arange(12).reshape((3,4)) In [116]: a Out[116]: array([[ 0, 1, 2, 3], ...

  5. Numpy系列(三)- 基本运算操作

    Numpy 中数组上的算术运算符使用元素级别.最后的结果使用新的一个数组来返回. import numpy as np a = np.array( [20,30,40,50] ) b = np.ara ...

  6. java学习之—递归实现二分查找法

    /** * 递归实现二分查找法 * Create by Administrator * 2018/6/21 0021 * 上午 11:25 **/ class OrdArray{ private lo ...

  7. 【学习】通用函数:快速的元素级数组函数【Numpy】

    通用函数(即ufunc)是一种对ndarray中的数据执行元素级运算的函数.可以将其看做简单函数(接受一个或多个标量值,并产生一个或多个标量值)的矢量化包装器. sqrt 和 exp为一元(unary ...

  8. php 阳历转农历优化版

    网上转换方法很多例子错误. 测试例子1:输入公历 2010年2月1号测试,对比百度万年历 农历应该为己丑年(2009)腊月(12月)十八. 测试例子2:输入农历1990.11.初十,丑时,公历应该为1 ...

  9. CI框架 -- 密码哈希

    哈希算法是一个单向函数.它可以将任何大小的数据转化为定长的“指纹”,并且无法被反向计算 依赖性 crypt() 函数需支持 CRYPT_BLOWFISH 常量 PASSWORD_BCRYPT PASS ...

随机推荐

  1. java se

    集群 数据库集群.服务器集群.内存 java特性 封装:封装细节和封装变化(可能发生需求变更的代码必须要封装,set方法除了完成赋值功能外,还能处理额外的任务,记录访问的人) 继承 多态 访问限定符 ...

  2. 十、SAP小数需要用引号括起来

    一.我们定义一个浮点型f的变量,然后赋值,检查会报错 二.我们把引号括起来之后,就正常了,如下: 三.输出效果如下: 注意:f类型的变量,输出不是准确值

  3. python --- excel文件处理

    1.安装第三方库:openpyxl 2.操作示例 from openpyxl import load_workbook #.打开文件 file = load_workbook("test.x ...

  4. PHP上传图片,路径保存在数据库中,根据图片路径显示图片

    1.创建数据表   CREATE TABLE image( id int(4) unsigned NOT NULL AUTO_INCREMENT, name varchar(100) default ...

  5. my97datepicker实现日期改变立刻触发函数

    <input type="text" class="Wdate" onclick="WdatePicker({onpicking:functio ...

  6. (1) JVM内存管理:内存模型

    引子 一段简单的代码结果引发疑问,==到底比较的是什么?equals呢? public static void main(String args[]){ String s1="abc&quo ...

  7. java中的字符串String

    一.String简介d 参考:https://www.cnblogs.com/zhangyinhua/p/7689974.html String类代表字符串. java.lang.String: Ja ...

  8. MVC学生管理系统-阶段V(模糊查询)

    项目源码 :https://download.csdn.net/download/weixin_44718300/11091042 此处省略一段话.去上一篇查看 NO01:修改list.jsp < ...

  9. C#后台执行JavaScript

    方法一: Page.RegisterClientScriptBlock 方法 命名空間: System.Web.UI 这个方法现在已经过时.改用ClientScriptManager.Register ...

  10. Beyond Compare 文件对比工具的使用

    Beyond Compare 文件对比工具的使用 Beyond Compare 工具下载地址: http://www.onlinedown.net/soft/633850.htm 本文下载地址:E:\ ...