【LeetCode】Remove Duplicates from Sorted Array
来源:互联网 发布:陈道明 传承者 知乎 编辑:程序博客网 时间:2024/05/16 05:28
description:
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]
class Solution {public: int removeDuplicates(int A[], int n) { // Note: The Solution object is instantiated only once and is reused by each test case. //int *end = unique(A,A+n); //return end -A; if(n == 0) return 0; if(n == 1) return 1; int i = 0,j = 1; for(; j<n; j++) { if(A[j] != A[i]) { A[++i] = A[j]; } } return i+1; }};
- [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
- vb.net 将数据库中的内容显示到comboBox中的代码
- 程序员面试之道(《程序员面试笔试宝典》)之如何与企业进行待遇谈判?
- ServletContext总结
- java集合类之ArrayList
- 关于sizeof
- 【LeetCode】Remove Duplicates from Sorted Array
- epoll的LT和ET模式
- CODE 58: Sort Colors
- 【分享】Java学习之路:不走弯路,就是捷径
- 感觉越来越懂得生活
- 用英语数数
- OnClickListener的不同用法
- 给定任意一个正整数,求比这个数大且最小的不重复数,“不重复数”的含义是相邻两位不同(java写的)
- 用AJAX刷新一个DIV中的jsp内容