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. 12.Python的高级语法和用法

    # from enum import Enum # 枚举 # class VIP(Enum): # YELLOW = # YELLOW_ALIAS = # 别名 # GREEN = # BLACK = ...

  2. 二十一、SAP中通过内表输出数据库中数据

    一.我们查看一个SCARR的一个数据库 二.数据库内容如下 三.我们写一个关于内表使用的代码,来显示这个数据库内容 四.输出如下

  3. web前端知识点

    一.CSS问题 1.flex布局 display:flex; 在父元素设置,子元素受弹性盒影响,默认排成一行,如果超出一行,按比例压缩 flex:1; 子元素设置,设置子元素如何分配父元素的空间,fl ...

  4. 可并堆模板题-mergeable heap

    Description 有n个点,第i个点标号为i,有两种操作:0 x y 表示把x所在堆和y所在堆合并.1 x 表示询问x所在堆的最小权. Input 第一行两个整数n,m,表示有n个点m个操作. ...

  5. vue-router 二级路由(父子路由)

    使用二级路由 会显示父路由下面的子路由  且父子路由同时显示 因为父子同时显示  路由地址在同一级别/ 路由的显示模式有两种(都是为了减少数据库后台请求次数) #hash模式(#是特殊字符,很多场合不 ...

  6. jQuery琐碎

    函数(以click事件为例)在jsp页面和js中的不同写法 onclick="getInfo(this);" function getInfo(obj){ var $this=$( ...

  7. PythonTwo

    格式化输出: % 占位符  s(str 字符串) d(digit 数字)  %% 只单纯显示% Str 索引切片 captlze  首字母大写 upper 全大写 lower 全小写 find 通过元 ...

  8. BZOJ:1927: [Sdoi2010]星际竞速

    题解:最小费用流+二分图模型: 左边表示出这个点,右边表示入这个点: #include<iostream> #include<cstdio> #include<cstri ...

  9. LabVIEW面向对象的ActorFramework(3)

    四.LabVIEW面向对象的编程架构:Actor Framework Actor Framework是一个软件类库,用以支持编写有多个VI独立运行且相互间可通信的应用程序,在该类型应用程序中,每个VI ...

  10. 创建Oracle序列sequence

    create sequence SEQ_ID minvalue 1 maxvalue 99999999 start with 1 increment by 1 nocache order; 建解发器代 ...