【leetcode 数组】Remove Duplicates from Sorted Arrayd
来源:互联网 发布:工地临时用电计算软件 编辑:程序博客网 时间:2024/04/20 14:08
题目:
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]
.
分析:
遍历一遍,首先找到与A[0]不等的,放到A[1],再找与A[1]不等的,放到A[2],以此类推
代码参考:
class Solution {public: int removeDuplicates(int A[], int n) { if(n==0) return 0; int m=0; for(int i=1;i<n;i++) { if(A[m]!=A[i]) { m++; A[m]=A[i]; } } return m+1; }};
0 0
- 【leetcode 数组】Remove Duplicates from Sorted Arrayd
- 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 ArrayII 数组去重II
- 【leetcode 数组】Remove Duplicates from Sorted Array II
- [leetcode]【数组】26. Remove Duplicates from Sorted Array
- [leetcode]【数组】80. Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted List :from LeetCode
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted Array
- LeetCode: Remove Duplicates from Sorted List II
- 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 List
- [Leetcode] Remove Duplicates from Sorted List II
- 01-SD卡烧写Linux系统v3.0.1
- 【JavaScript】表单即时验证,不成功不让提交
- TRIZ系列-创新原理-28-替代机械系统原理
- MFC对话框编程详细学习笔记
- Java利用Zxing生成二维码
- 【leetcode 数组】Remove Duplicates from Sorted Arrayd
- java中华调用memcached
- JAVA学习第五十课 — IO流(四)转换流
- 全面解析SQL SERVER 的左右内连接
- soj 11598. XOR
- vim自动补全插件snipMate在ubuntu下的安装
- Linux——线程信号量 读写锁 线程的私有数据
- 我的学生作业2
- SQL-有条件查询数据