LeetCode-Remove Duplicates from Sorted Array
来源:互联网 发布:紫格尼克效应 知乎 编辑:程序博客网 时间:2024/06/05 12:49
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]
.
Code:
<span style="font-size:14px;">class Solution {public: int removeDuplicates(int A[], int n) { if (n == 0 || n == 1) return n; int begin = 0, end = 1, length = 1; while (end < n) { if (A[begin] != A[end]) { ++length; ++begin; A[begin] = A[end]; } ++end; } return length; }};</span>
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
- Linux 密码文件详解
- UVA - 10497 Sweet Child Makes Trouble
- Python中super关键字的作用
- POJ 3691 DNA repair 基于AC自动机的DP
- 带通配符的数
- LeetCode-Remove Duplicates from Sorted Array
- Python之美[从菜鸟到高手]--NotImplemented小析
- Codeforces Round #261 (Div. 2)
- 2015年华为提前招聘机试题--查找完数
- UVA - 297 Quadtrees
- 线性表之连续存储(数组)
- LeetCode 93 Restore IP Addresses
- 出错1Exception in thread "main" java.io.IOException: Cannot run program "C:\winmine.e xe": CreateProce
- hdu 4948 kingdom