Remove Duplicates from Sorted Array
来源:互联网 发布:张绍飞矩阵论教程课件 编辑:程序博客网 时间:2024/06/16 23:42
题目
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 = A.length; if(len < 2){ return len; } int end = 0; for(int i = 1; i < len; i ++){ if(A[end] != A[i]){ end++; A[end] = A[i]; } } return end + 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
- 微信公众平台开发教程第21篇-“可信网址”白名单
- 【十大数据挖掘算法】C4.5决策树
- Spark1.0.0 生态圈一览
- 动态规划之装配线调度
- 联想A800新蜂ROM刷机包 官方4.0.4优化 精简省电稳定 V1.2
- Remove Duplicates from Sorted Array
- 我的手机-我的嵌入式-3
- <CSS基础>导航栏制作教程
- LA 3126 - Taxi Cab Scheme DAG上的二分匹配
- 当我闲困的时候,我在想些什么
- [Android]appcompat_v7
- Linux下多线程程序调试方法
- jsp绝对路径
- Linux C 获取当前应用程序的绝对路径