1.这个题不难,关键在于把题目意思理解好了。这个题问的不清楚。要求return new length,很容易晕掉。
其实就是return 有多少个单独的数。

import java.util.Arrays;

/*
* Question: Given a sorted array,remove the duplicates in place such that each element
* appear only once and return the new length
*
* Do not allocate extra space for another array, you must do this in place with constant memory.
*/
public class RemoveDuplicatesfromSortedArray {
public static void main(String[] args){
int[] nums = new int[]{1,1,2};
removeDuplicates(nums);
}
public static int removeDuplicates(int[] nums){
if(nums == null || nums.length == 0){
return 0;
}
int index = 1;
for(int i=1 ;i<nums.length;i++){
if(nums[i] != nums[i-1]){
index ++;
}
}
nums = Arrays.copyOf(nums, index); return index;
}
public static int removeDuplicatesWorking(int[] nums){ return 0;
}
}

Integer Array Ladder questions的更多相关文章

  1. zenefits oa - sort integer array in lexographical order

    [ 12 | 2434 | 23 | 1 | 654 | 222 | 56 | 100000 ] Then the output should be: [ 1 | 100000 | 12 | 222 ...

  2. Equal Sides Of An Array

    参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...

  3. array题目合集

    414. Third Maximum Number 给一个非空的整数数组,找到这个数组中第三大的值,如果不存在,那么返回最大的值.要求时间复杂度为o(n) 例如: Example 1: Input: ...

  4. [LeetCode] 330. Patching Array 数组补丁

    Given a sorted positive integer array nums and an integer n, add/patch elements to the array such th ...

  5. [LeetCode] 805. Split Array With Same Average 用相同均值拆分数组

    In a given integer array A, we must move every element of A to either list B or list C. (B and C ini ...

  6. LeetCode面试常见100题( TOP 100 Liked Questions)

    LeetCode面试常见100题( TOP 100 Liked Questions) 置顶 2018年07月16日 11:25:22 lanyu_01 阅读数 9704更多 分类专栏: 面试编程题真题 ...

  7. [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  8. [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  9. [LeetCode] Patching Array 补丁数组

    Given a sorted positive integer array nums and an integer n, add/patch elements to the array such th ...

随机推荐

  1. sysctl-p报错:error: "net.bridge.bridge-nf-call-ip6ta

    1.刚配置完sysctl,加载时报错:[root@itpux1 yum.repos.d]# sysctl -pnet.ipv4.ip_forward = 0net.ipv4.conf.default. ...

  2. 开源项目初涉(C++自我学习开始)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://i.cnblogs.com/EditPosts.aspx?postid=8428885 临近2018农历新年,我还在上班,哈哈. ...

  3. 安装Caffe纪实

    第一章 引言 在ubuntu16.04安装caffe,几乎折腾了一个月终于成功;做一文章做纪要,以便日后查阅.总体得出的要点是:首先,每操作一步,必须知道如何检验操作的正确性;笔者的多次失误是因为配置 ...

  4. 一分钟搭建Spring Boot

    1.首先你的电脑需要安装jdk.Apache Maven.Intellij IDEA 2.新建项目  (敲重点,有的同学有没有Spring Initializr 这个请到本文章后面看安装步骤) 3.选 ...

  5. 【391】栈与队列,Python实现

    参考:python实现stack(栈)和队列(queue) - hjhmpl123的博客 - CSDN博客 参考:Python3 数据结构 | 菜鸟教程 栈和队列是两种基本的数据结构,同为容器类型.两 ...

  6. ELK6.0部署:Elasticsearch+Logstash+Kibana搭建分布式日志平台

    一.前言 1.ELK简介 ELK是Elasticsearch+Logstash+Kibana的简称 ElasticSearch是一个基于Lucene的分布式全文搜索引擎,提供 RESTful API进 ...

  7. Swagger注解

    swagger注解说明  1.与模型相关的注解,用在bean上面 @ApiModel:用在bean上,对模型类做注释: @ApiModelProperty:用在属性上,对属性做注释 2.与接口相关的注 ...

  8. android studio 创建图标

    参考 https://www.cnblogs.com/c546170667/p/5975550.html File-New-Image Asset

  9. RDD认知

    1.RDD又叫弹性分布式数据集 2.抽象 3.带泛型,支持多种数据类型 4.集合是可以进行分区 例如(1,2,3,4,5,6,7,8,9)这个数组是可以进行分区的(1,2,3)  (4,5,6)  ( ...

  10. KALI安装与环境配置

    2018-2019 201899224<网络攻防实践>第二周作业 虚拟化网络攻防实验环境包括以下部分: 靶机:包含系统和应用程序安全漏洞,并作为攻击目标的主机.(Windows XP和Li ...