Remove Duplicates from Sorted Array
来源:互联网 发布:淘宝女装店铺简介范文 编辑:程序博客网 时间:2024/05/18 02:08
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 nums = [1,1,2]
,
Your function should return length = 2
, with the first two elements of nums being 1
and 2
respectively. It doesn't matter what you leave beyond the new length.
public class Solution { public int removeDuplicates(int[] nums) { int length=nums.length; if(length==0) return 0; int pos=0; nums[pos]=nums[0]; for(int i=1;i<length;i++) { if(nums[i]!=nums[pos]) nums[++pos]=nums[i]; } return pos+1; }}
0 0
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates From Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- django 1.8 官方文档翻译: 2-5-2 进行原始的sql查询
- Spring官网改版后下载
- 指令系统
- 类、方法 类的继承与方法重写
- 0x3f3f3f3f--无穷大
- Remove Duplicates from Sorted Array
- 数据结构面试题总结1——数组:求最大、次大值
- 4th Oct 2014:R语言中的factor类型
- 反病毒工具-WinDBG
- 【数据结构】栈的应用--括号的匹配(c++)
- 寻址规则
- C语言中%s,%5.3s,%e,%10.2e的意思
- cmd创建wifi
- 查看端口被占用