LeetCode 2.1.1 Remove Duplicates from Sorted Array
来源:互联网 发布:淘宝第三方网购平台 编辑:程序博客网 时间:2024/05/16 10:33
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].
public class Solution {
public int removeDuplicates(int[] A) {
int index = 0;
for(int i = 0;i < A.length; i++){
if(i > 0 && A[i] == A[i - 1])
continue;
A[index ++] = A[i];
}
return index;
}
}
0 0
- LeetCode 2.1.1 Remove Duplicates from Sorted Array
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】Remove Duplicates from Sorted Array
- 2.1.1 Remove Duplicates from Sorted Array
- 2.1.1 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
- df就会发飞华健康沙迪克就
- 关于今晚解题后的感想
- Hackerrank Connected Cell in a Grid
- nginx/php-fpm 访问php文件直接下载而不运行
- LeetCode 2.1.2 Remove Duplicates from Sorted Array II
- LeetCode 2.1.1 Remove Duplicates from Sorted Array
- C++游戏之游戏动画的实现(三)
- 深刻的印象
- 还未来得及
- 绿条长带雪
- 还能翻出什么花来……”
- 必知必会
- 数学三大危机
- 矩阵相乘