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 int removeDuplicates(int[] A) {
int len = 0;
int temp;
for (int i = 0; i < A.length; ) {
temp = A[i];
while (A[i] == temp) {
i++;
if (i == A.length)
break;
}
A[len] = temp;
len++;
}
return len;
}

LeetCode——Remove Duplicates from Sorted Array的更多相关文章

  1. LeetCode:Remove Duplicates from Sorted Array I II

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

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

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

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

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

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

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

  5. [LeetCode]Remove Duplicates from Sorted Array题解

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

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

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

  7. [LeetCode] Remove Duplicates from Sorted Array II [27]

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

  8. [leetcode]Remove Duplicates from Sorted Array II @ Python

    原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题意: Follow up for &quo ...

  9. [LeetCode] Remove Duplicates from Sorted Array

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

随机推荐

  1. [转] STL源码学习----lower_bound和upper_bound算法

    http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html PS: lower_bound of value 就是最后一个 < ...

  2. iOS人脸识别(CoreImage)

    1.从初始UIImage获取一个CIImage对象. 2.创建一个用于分析对象的CIContext. 3.通过type和options参数创建一个CIDetector实例. type参数指定了要识别的 ...

  3. android基础篇学习心得

    android技术中,线程.进程.JNI.IPC和各个小框架结构是基本功.在跟随高焕堂老师的android程序猿到架构师之路系列视频中 学习完基础篇之后,颇有些心得,记录下来. android开发就是 ...

  4. Python之路,Day23-----暂无正在更新中

    Python之路,Day23-----暂无正在更新中

  5. JS HTML 单引号与双引号

    JS中,单引号和双引号其实没啥区别,看你自己习惯了. 但若双引号中再使用双引号,我们可采取"外双内单"或者"外单内双"的格式,当然如果需要的是双引号本身,则只能 ...

  6. Android客户端与服务端交互之登陆示例

    Android客户端与服务端交互之登陆示例 今天了解了一下android客户端与服务端是怎样交互的,发现其实跟web有点类似吧,然后网上找了大神的登陆示例,是基于IntentService的 1.后台 ...

  7. excel数据导入到sqlserver中---------工作笔记

    调用页面: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sys ...

  8. application/json IE 兼容问题

    由于IE系列浏览器把application/json响应视为文件,并尝试下载在网上看了一下,大致了解,只要修改返回的内容的类型(ContentType)即可解决问题. 由于ajax请求,返回类型默认就 ...

  9. JS加入收藏与设置主页

    收藏: <a href="javascript:void(0)" onclick="shoucang(document.title,window.location) ...

  10. Ext Sencha Cmd 6 环境安装

    Sencha Cmd安装笔记 在使用前端框架ExtJs前,需对其环境加以部署,对自己的安装过程加以记录. 建议大家在安装时,最好使用VPN,个中缘由,生在跳槽的程序袁应该都懂吧.不然ruby相关命令执 ...