题目

     题目要求:去除sort int数组中的重复项。

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.

For example,
Given input array A = [1,1,2],

Your function should return length = 2, and A is now [1,2].

代码

public class Solution {public int removeDuplicates(int[] A) {if (A.length==0) return 0;int length =A.length;int[] B=new int[length];int index=0;//B指向下一个位数int temp=0;//B已经赋值的位置for(int i=0;i<length;i++){//如果第一项是零的情况{0,0,2}if(A[i]==0 && index==0){B[index]=0;index+=1;}if(A[i]!=B[temp]){B[index]=A[i];temp=index;index+=1;}                      }//给A赋值for(int k=0;k<index;k++){A[k]=B[k];}return index;}
}
代码下载:https://github.com/jimenbian/GarvinLeetCode

/********************************

* 本文来自博客  “李博Garvin“

* 转载请标明出处:http://blog.csdn.net/buptgshengod

******************************************/

【LeetCode从零单排】No26.Remove Duplicates from Sorted Array相关推荐

  1. leetcode python3 简单题26. Remove Duplicates from Sorted Array

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二十六题 (1)题目 英文: Given a sorted array nums, ...

  2. Remove Duplicates from Sorted Array II -- LeetCode

    原题链接: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/  这道题跟Remove Duplicates ...

  3. LeetCode集锦(八) - 第26题 Remove Duplicates From Sorted Array

    LeetCode集锦(八) - 第26题 Remove Duplicates From Sorted Array 问题 Given a sorted array nums, remove the du ...

  4. LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] c++

    LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...

  5. LeetCode算法入门- Remove Duplicates from Sorted Array -day21

    LeetCode算法入门- Remove Duplicates from Sorted Array -day21 题目描述 Given a sorted array nums, remove the ...

  6. [Leetcode] Remove duplicates from sorted array ii 从已排序的数组中删除重复元素

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

  7. Leetcode OJ: Remove Duplicates from Sorted Array I/II

    删除排序数组重复元素,先来个简单的. Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates i ...

  8. LeetCode 80. Remove Duplicates from Sorted Array II

    80. Remove Duplicates from Sorted Array II My Submissions QuestionEditorial Solution Total Accepted: ...

  9. 2016.6.17——Remove Duplicates from Sorted Array

    Remove Duplicates from Sorted Array 本题收获: 1."删除"数组中元素 2.数组输出 题目: Given a sorted array, rem ...

最新文章

  1. 【Chat】实验 -- 实现 C/C++下TCP, 服务器/客户端 多人聊天室
  2. 网站服务器的解决方案有,Web网站服务器DDOS攻击的解决方案
  3. Python 一键导出微信阅读记录和笔记,666!
  4. Python网络编程、爬虫之requests模块使用
  5. 希捷低格工具_拯救硬盘问题的终极大招超强电脑硬盘低格工具
  6. 老男孩linux——36期学员
  7. BIGEMAP教您如何选择分度带(中央子午线)
  8. 六行shell脚本实现Android手机自动刷抖音极速版
  9. 如何查看虚拟机服务器ftp,如何通过FTP工具查看虚拟空间使用了多少?
  10. Android红外功能模拟触摸鼠标事件唤醒屏幕
  11. 【FPGA】:ip核---乘法器(multiplier)
  12. Flutter问题记录 - Unable to find bundled Java version
  13. php 计算从开始时间到结束时间 总共有多少天
  14. 人人皆可操作的108个抖音项目:汽车领域细分及玩法变现 (7)
  15. 经典不等式链的一些拓展理解
  16. 问题-fuxi job failed ,cased by:Invalid decimal format.
  17. 读曾仕强《管理的方与圆》笔记三
  18. java web调用百度地图_Java web与web gis学习笔记(二)——百度地图API调用
  19. Eclipse下Tomcat项目自动部署路径问题(.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps)
  20. 华为鸿蒙新机2k曲面屏,华为mate30概念新机:2K曲面屏+麒麟985+鸿蒙OS系统 国产机皇来袭...

热门文章

  1. mapinfo制作地图_用QGIS代替Mapinfo软件
  2. tp5上传文件并获取文件路径_thinkphp表单上传文件并将文件路径保存到数据库中...
  3. 2022我会成为高手吗
  4. c语言交换a b(运算符),关于编程语言:是否有一个复合赋值运算符用于a = b
  5. linux wc -l 对io,linux设备驱动归纳总结(五):2.操作硬件——IO内存
  6. java阅读题_java 练习题带答案
  7. tem在c语言中的作用,Temtem状态有什么效果 Temtem各状态效果介绍_游侠网
  8. 字符串匹配算法Java_如何简单理解字符串匹配算法?
  9. java程序不能编译_救命-JAVA程序不能编译!
  10. mysql jdbc 协议_JDBC-MySql