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. pyinstaller打包PySide2写的GUI程序,调用ffmpeg隐藏CMD控制台解决方案

    1 问题描述 使用PySide2写了一个GUI程序,调用ffmpeg命令行工具,做简单的批量视频处理(调整帧宽度.帧高度.视频变速.降低视频码率达到限制视频大小),使用了ffmpeg. ffmpeg- ...

  2. Spring-IOC(基于注解)

    1.Spring 的 Bean 管理:(注解方式) 1.1 创建 web 项目,引入 Spring 的开发包: 注:在 Spring 的注解的 AOP 中需要引入 spring-aop 的 jar 包 ...

  3. 147-PHP strip_tags函数,剥去字符串中的 HTML 标签(一)

    <?php $html=<<<HTM <title>PHP输出HTML代码</title> <body> <a href=#>转 ...

  4. opencv运动物体识别

    import cv2 import time import datetime import os def mkdir(path): folder = os.path.exists(path) if n ...

  5. python练习(一)----打印九九乘法表

    打印九九乘法表 ,): ,i+): print("{0} x {1} = {2} \t".format(j,i,i*j),end='') //print默认end=‘\n’, pr ...

  6. microsoft help viewer 收藏夹功能

    平时重装系统比较多,重装后,microsoft help viewer 2.0里面的收藏就丢失了,要恢复以前的收藏,可以直接在C:\Users\ZR\AppData\Local\Microsoft\H ...

  7. oracle数据库语言(1)--数据定义语言

      1.数据定义语言 (DDL)DATE DEFINITION LANGUAGE 作用是用于增删改 数据库对象 (1) 创建表格 CREATE TABLE EMP ( -------创建 名为 EMP ...

  8. Win7 node多版本管理gnvm采坑记录

    采坑描述:下载新node版本及切换node失败 解决:1.要用管理员权限启动cmd:2.确保node是空闲的 Gnvm下载地址: 32-bit | 64-bit Github 1.下载之后为 得到一个 ...

  9. Codeforces 433C #248_div1_A 中位数的应用

    擦..今天这套题好尼玛难啊,做了一个小时,连一题都没做出来,而且还没什么头绪 查了下出题人,师大附中的 14年毕业 13年拿到的国家集训队资格 保送清华 题意是 给一串序列,计算一个值,这个值是 相邻 ...

  10. qt 字符串 转换 hex

    1. qt 中两个字符的字符串直接转换为 hex,类似于 "1A" 要转换成 16进制的 0x1A,使用 int QString::toInt(bool *ok, int base ...