remove-duplicates-from-sorted-array
来源:互联网 发布:贪心算法 多机调度 编辑:程序博客网 时间:2024/05/17 03:05
packagecom.ytx.array;
/** 题目: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].
*@authoryuantian xin
*
* 给你一个有序数组,返回去除重复元素后数组的长度。不允许申请新的空间。
* 思路:
*
*/
publicclass Remove_duplicates_from_sorted_array {
publicintremoveDuplicates(int[]A) {
intlen = A.length;
if(len== 0 || A == null ) return0;
int index = 1;
for (inti = 1; i < len; ++i) {
if (A[i] ==A[i- 1]) {
continue;
}
A[index++] =A[i];
}
returnindex;
}
publicstatic void main(String[]args) {
/*int[] A = {1,2,2,3,3,4,4,5,6,7,9,9};*/
intA[] = {1};
System.out.println(newRemove_duplicates_from_sorted_array().removeDuplicates(A));
for(inti = 0; i < A.length;i++) {
System.out.print(A[i]);
}
}
}
阅读全文
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
- vim YouCompleteMe不能自动提示
- 最最最好看的科幻电影集结地
- docker学习——tomcat安装
- Win10搭建TensorFlow-GPU版的框架
- Android消息处理机制(二):循环和消息队列的创建
- remove-duplicates-from-sorted-array
- 背包初级+贪心
- Centos6.5系统下Apache2.4.27的安装过程
- Java 高级特性: Lambda 表达式
- 反馈式学习plus
- SPFA 算法详解( 强大图解,不会都难!)
- 2017.9.3
- jedis 连接池工具类具体实现demo。
- Linus实验楼笔记——第9节:Linux任务计划crontab