/*
@Copyright:LintCode
@Author:   Monster__li
@Problem:  http://www.lintcode.com/problem/remove-duplicates-from-sorted-array
@Language: Java
@Datetime: 17-03-02 11:26
*/

public class Solution {
    /**
     * @param A: a array of integers
     * @return : return an integer
     */
    public int removeDuplicates(int[] nums) {
        // write your code here
        int i,k,length=nums.length;
  //显示元数组
  /*System.out.println("元数组为:");
  for(i=0;i<length;i++)
  {
   System.out.print(nums[i]+" ");
  }*/
  //找到重复的数字,并将后面所有元素前移一位
  for(i=0;i<length-1;i++)
  {
   if(nums[i+1]==nums[i])
   {
    for(k=i+1;k<length-1;k++)
    {
     nums[k]=nums[k+1];
    } 
    length--;
    nums[k]=-1;
    i--;
   }
  }
  //A[i]=(-1);
  //输出处理后的数组
 // System.out.println("\n处理后的数组为:");
  /*for(i=0;i<length;i++)
  {
   System.out.print(nums[i]);
  }*/
  return length;
    }
}

100_remove-duplicates-from-sorted-array的更多相关文章

  1. [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

  2. [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  3. Remove Duplicates From Sorted Array

    Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...

  4. 【leetcode】Remove Duplicates from Sorted Array II

    Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...

  5. 26. Remove Duplicates from Sorted Array

    题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  6. 50. Remove Duplicates from Sorted Array && Remove Duplicates from Sorted Array II && Remove Element

    Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...

  7. LeetCode:Remove Duplicates from Sorted Array I II

    LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...

  8. 【26】Remove Duplicates from Sorted Array

    [26]Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such th ...

  9. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法

    Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...

  10. [Leetcode] Remove Duplicates From Sorted Array II (C++)

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...

随机推荐

  1. 【2-23】分支语句(switch…case)及循环语句

    Switch-case分支语句与if语句作用相同,但需将情况都罗列出比较麻烦所以不常用. 其基本结构是: Switch(一个变量值) { Case 值1:要执行的代码段:break; Case 值2: ...

  2. UI 自定义视图 ,视图管理器

    一>自定义label - textField 视图 自定义视图:系统标准UI之外,自己组合而出的新的视图 iOS 提供了很多UI组件 ,借助它们,我们可以做各种程序 尽管如此,实际开发中,我们还 ...

  3. oracle xe 数据库用户操作

    在system账号登录获得system权限,然后对用户进行操作 --创建表空间create tablespace tablespace_name datafile 'D:\tablespace_nam ...

  4. 你的外接键盘的小键盘在Num Lock键亮着的,但是数字按了不能用,解决办法在这里

    1.可能是Num Lock键卡住了导致的,你多按几次numlock键试试. 如果上面的不行,你就再试试下面的这个: 2.系统下开启了启用鼠标键导致的,解决的方法如下: (1).打开"控制面板 ...

  5. Java的内存机制详解

    Java把内存分为两种:一种是栈内存,另一种是堆内存.在函数中定义的一些基本类型的变量和对象的引用变量都是在函数的栈内存中分配,当在一段代码块定义一个变量时,Java 就在栈中为这个变量分配内存空间, ...

  6. 混合高斯模型(GMM)推导及实现

    作者:桂. 时间:2017-03-20  06:20:54 链接:http://www.cnblogs.com/xingshansi/p/6584555.html 声明:欢迎被转载,不过记得注明出处哦 ...

  7. 关于数组和集合的冒泡排序中容易出现的IndexOutOfBoundsException

    数组只能存错一种相同的数据类型,集合只能存储引用数据类型(用泛型),集合的底层就是一个可变的数组. 数组的冒泡排序: public static void arrayMaxPaiXu(int[] ar ...

  8. UWP Composition API - New FlexGrid 锁定行列

    如果之前看了 UWP Jenkins + NuGet + MSBuild 手把手教你做自动UWP Build 和 App store包 这篇的童鞋,针对VS2017,需要对应更新一下配置,需要的童鞋点 ...

  9. Unity3D动态读取外部MP3文件给AudioSource

    在PC端VR游戏开发中,需要动态加载本地的MP3文件,但是Unity3D不知道出于什么原因,到5.4.0也不支持MP3文件的外部加载(目前只支持wav和ogg). 因此要想通过www来加载mp3文件就 ...

  10. 【转】如何实现Flex页面跳转

    其实对于这个题目是不恰当的,因为flex中是没有页面这个概念的,页面在flex里面其实就是一个个的Canvas,vbox,hbox等等之类的东西,看到的不同页面的切换,就是这些元素一层层的堆积,或者替 ...