Remove Duplicates from Sorted Array
来源:互联网 发布:外贸服装 知乎 编辑:程序博客网 时间:2024/06/10 02:57
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 class Solution { public int removeDuplicates(int[] A) { int i = 0; int j = 1; if (A.length == 0){ return 0; } while (i < A.length ){ while (j < A.length && (A[i] == A[j])){ j ++; } if (j == A.length){ break; } A[++ i] = A[j ++]; } return i + 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
- 复杂度1. 最大子列和问题
- debian下安装mysql
- MVC和普通三层的区别
- Java JSON技术框架选型与实例
- 年轻辣妈网上走红 亲授英语学习方法秒杀学霸
- Remove Duplicates from Sorted Array
- OpenGL实现通用GPU计算概述
- 第四周【项目1-三角形类的构造函数】(4)
- php 开发手机app接口
- vim常用命令(iOS)
- SPOJ694--- DISUBSTR - Distinct Substrings(后缀数组)
- 关于光标放到链接上的时候,会变成手型
- ajax异步数据应用示例
- android网络框架volley学习之RequestQueue类