LeetCode: Remove Duplicates from Sorted Array
来源:互联网 发布:网络推广转化率 编辑:程序博客网 时间:2024/04/29 06:54
Given a sorted array, remove the duplicates in place such that each element appear onlyonce 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) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n <= 1){return n;} int pos = 0; for(int i = 0; i< n; ++i){ while(i < n- 1 && A[i] == A[i +1]){ i++; } A[pos++] = A[i]; } return pos; }};
- [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
- vc之字符类型区别
- 【PB】程序中在普通激光打印机上实现条码打印
- 开源 3D CAD 软件 - gCAD3D 1.9.1 发布
- [Leetcode] Remove Duplicates from Sorted List II
- C#希尔排序算法
- LeetCode: Remove Duplicates from Sorted Array
- 51的中断程序用C怎么写
- 关于IE 延迟加载activex和插件未激活问题。
- vc++之CSize
- 期末考试月来临,各种大作业啊
- Java 文件上传组件 Apache Commons FileUpload 应用指南
- ie6,ie7,ie8 css bug兼容解决方法
- LeetCode: Remove Duplicates from Sorted Array II
- Blender 三维绘图及渲染软件(优秀强大跨平台遵循 GPL 许可证)