Leetcode-remove-duplicates-from-sorted-array
来源:互联网 发布:使命召唤14数据不兼容 编辑:程序博客网 时间:2024/05/29 23:46
题目描述
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].
这个题目非常具有代表性,数组的元素移位,以后需要记住该方法,定义一个size指针,遇到与上一个数据不同的,size加一个。
代码如下:
public class Solution { public int removeDuplicates(int[] A) { int size = 0; for(int i=0; i<A.length; i++) { if(A[i] != A[size]) { A[++size] = A[i]; } } return size+1; }}
0 0
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- leetcode 35: Remove Duplicates from Sorted Array
- [LeetCode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array
- Leetcode: Remove Duplicates from Sorted Array
- [leetcode] Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array
- [LeetCode]Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array
- [leetcode]Remove Duplicates from Sorted Array II
- 免费学桌面工程师、系统工程师、系统运维工程师
- 软件静默安装命令大全
- 部署Exchange 2013
- IPython 的使用
- Lync Server 2013 Prerequisite installation failed
- Leetcode-remove-duplicates-from-sorted-array
- Apache Zeppelin安装及介绍
- Lync 2013 Unauthorized: Access is denied due to a RBAC authorization Failure
- oracle中的exists 和not exists 用法详解
- AD默认和扩展属性 Get-ADUser Default and Extended Properties
- 设计模式GOF23——代理模式
- win 7 电脑快捷键总结整理
- Windows管理员常用的PowerShell命令
- exchange 2013 客户端不能自动发现