[leetcode] Remove Duplicates from Sorted Array
来源:互联网 发布:七天网络怎么绑定不了 编辑:程序博客网 时间:2024/06/05 03:24
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,用后面的数字将前面重复的数字覆盖
代码:
class Solution {public: int removeDuplicates(int A[], int n) { if(n==0) return 0; int j; for(int i=1;i<n;i++){ if(A[i]!=A[j]){ j++; A[j]=A[i]; } } return j+1; }};
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
- 利用SecureCRT上传、下载文件(使用sz与rz命令),超实用!
- 超详细教你怎么连接SAE mysql (有创建表的过程)
- Java环境配置 数据库 缓存Redis Nosql MongoDB 安装
- cout/cin(输出/输出)流限制输出宽度
- error storage size of 'pwbuf' isn't known
- [leetcode] Remove Duplicates from Sorted Array
- 云计算炙手可热,初学者如何入门
- Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等
- 磁盘坏道的处理
- JavaEE 技术选型建议,服务器配置,部署策略
- 与PHP通信
- 五.指针与结构
- UVA 239 - Tempus et mobilius. Time and motion(置换周期)
- 【转】细究lua闭包->搞清本质才是王道