LeetCode - Remove Duplicates from Sorted Array
来源:互联网 发布:vscode rails 编辑:程序博客网 时间:2024/06/05 04:28
Question:
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 static int removeDuplicates(int[] A) {int num = 0;if (A.length == 0) {return 0;}for (int i = 1; i < A.length; i++) {if (A[num] != A[i]) {A[++num] = A[i];}}num = num + 1;return num;}
0 0
- [leetcode][array] Remove Duplicates from Sorted Array
- 【Leetcode】【Array】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
- [LeetCode]Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array
- [leetcode]Remove Duplicates from Sorted Array II
- malloc和free函数详解
- struts2请求的URL的搜索路径的顺序概述
- ACCESS数据库防下载方法
- IOS第一个程序helloworld
- 删除重复字符 C++
- LeetCode - Remove Duplicates from Sorted Array
- http://blog.csdn.net/augusdi/article/details/8803099
- 项目部署到Tomcat报错
- C语言条件编译及编译预处理阶段
- C++中结构体类型(或则类类型)的大小
- String s = new String("xyz")创建了几个对象
- usaco training 4.2.4 Cowcycles 题解
- 函数参数的压栈过程
- C/C++堆、栈及静态数据区详解