【LeetCode OJ】Remove Duplicates from Sorted Array
题目: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) {
if(!n)
return NULL;
int i,num=;
for(i=;i<n;i++)
{
if(A[i]!=A[i-])
{
A[num++]=A[i];
}
}
return num;
}
};
【LeetCode OJ】Remove Duplicates from Sorted Array的更多相关文章
- 【LeetCode练习题】Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- LeetCode OJ 26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- LeetCode OJ 80. Remove Duplicates from Sorted Array II
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- LeetCode OJ:Remove Duplicates from Sorted Array II(移除数组中的重复元素II)
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 【26】Remove Duplicates from Sorted Array
[26]Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such th ...
- 【leetcode】Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
- [Leetcode][Python]26: Remove Duplicates from Sorted Array
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...
- C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array
26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...
随机推荐
- 【Html】网页获取屏幕宽高
<html> <script> function size(){ document.write( "屏幕分辨率为:"+screen.width+" ...
- 关于session_cache_expire 的理解
session_cache_limiter,它是session在客户端的缓存方式,有nocache,private,private_no_expire,publice主这几种. cache是属于浏览器 ...
- 使用Maven模板创建项目
在本教程中,我们将向你展示如何使用mvn archetype:generate从现有的Maven模板列表中生成项目.在Maven 3.3.3,有超过1000+个模板,Maven 团队已经过滤掉一些无用 ...
- e833. 获得JTabbedPane中的卡片
This example retrieves all the tabs in a tabbed pane: // To create a tabbed pane, see e828 创建JTabbed ...
- js中找string中重复项最多的字符个数
// split():字符串中的方法,把字符串转成数组. // sort():数组中的排序方法,按照ACALL码进行排序. // join():数组中的方法,把数组转换为字符串 function de ...
- CALayer: autoresizingMask
UIView 可以设定 autoresizingMask,当它的 superView 尺寸改变时,适应何种变化. 不过 CALayer 却没有这个属性,如和做到让 CALayer 和 UIView 一 ...
- categorys源码
CREATE TABLE `category` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `editdate` char(20) NOT NUL ...
- jQuery:jQuery性能优化28条建议
http://www.xue5.com/WebDev/jQuery/671700.html 直在寻找有关jQuery性能优化方面的小窍门,能让我那臃肿的动态网页应用变得轻便些.找了很多文章后,我决定将 ...
- linux command not found错误提示
错误提示:screen: command not found, 如果提示screen: command not found 命令不存在可以执行:yum install screen 或 apt-get ...
- win上的某个端口是否开启
1.添加Telnet服务 控制面板-->程序-->打开或关闭windows功能 2.配置Telnet为自动并开启服务 计算机-->服务和应用程序-->服务 3.telnet - ...