LeetCode——Remove Duplicates from Sorted Array
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的更多相关文章
- LeetCode:Remove Duplicates from Sorted Array I II
LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- [Leetcode] Remove Duplicates From Sorted Array II (C++)
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- [LeetCode]Remove Duplicates from Sorted Array题解
Remove Duplicates from Sorted Array: Given a sorted array, remove the duplicates in place such that ...
- [Leetcode] Remove duplicates from sorted array ii 从已排序的数组中删除重复元素
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Duplicates from Sorted Array II [27]
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- [leetcode]Remove Duplicates from Sorted Array II @ Python
原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题意: Follow up for &quo ...
- [LeetCode] Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
随机推荐
- Java 7之多线程- Semaphore--转载
Semaphore用于保存当前可用许可的数量.是通过共享锁实现的.根据共享锁的获取原则,Semaphore分为"公平信号量"和"非公平信号量". "公 ...
- 记录jpcap在Ubuntu&Window下的配置过程
众所周知,Java虽然在TCP/UDP传输方面给予了良好的定义,但是标准库java.net对于网络层以下的控制是无能为力的.Jpcap就是为了处理这一问题而出现的中间件.它调用底层的winpcap/l ...
- C#学习第六天
今天的内容主要是参数数组,C#允许函数指定一个(只能指定一个)特定的参数,这个参数必须是函数定义中最后一个参数,成为参数数组. 参数数组可以使用个数不定的参数调用函数,可以使用params关键字定义它 ...
- 12、SQL Server 行列转换
SQL Server 行转列 在SQL Server 2005中PIVOT 用于将列值转换为列名(行转列),在SQL Server 2000中是没有这个关键字的 只能用case语句实现. --创建测试 ...
- DataTable去重复方法
//去掉重复行 DataTable table=new DataTable(); DataView dv = table.DefaultView; table = dv.ToTable(true, n ...
- 【转】 UITableView 的indexPath
原文:http://blog.csdn.net/mengtnt/article/details/6733691 前面说过了viewController的一些基本注意事项.这里针对不同的viewCont ...
- java_annotation_01
一,Annotation简介 J2SE5.0提供了很多新的我,其中一个很重要的我就是对元数据的支持,在J2SE5.0中,这种元数据被称为注释,通过使用注释,程序开发人员可以在不改变原有逻辑的情况下,在 ...
- 二十分钟弄懂C++11 的 rvalue reference (C++ 性能剖析 (5))
C++ 11加了许多新的功能.其中对C++性能和我们设计class的constructor或assignment可能产生重大影响的非rvalue reference莫属!我看了不少资料,能说清它的不多 ...
- [LeetCode OJ] Reorder List—Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
For example,Given {1,2,3,4}, reorder it to {1,4,2,3}. /** * Definition for singly-linked list. * str ...
- 两个示例介绍JavaScript的闭包
JavaScript的闭包有两个用途:一个是访问函数内部的变量:另一个是让变量的值在作用域内保持不变.函数是JavaScript 中唯一有作用域的对象,因此JavaScript的闭包依赖于函数实现,下 ...