博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leetcode--Remove Duplicates from Sorted Array
阅读量:6995 次
发布时间:2019-06-27

本文共 533 字,大约阅读时间需要 1 分钟。

Problem 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].

分析:从有序数组中删除反复的元素,题目比較简单,能够利用两个下标i,j,用i记录如今第一个不反复的元素,然后利用j找到和i不同的元素,依次插入就可以。详细实现代码例如以下:

class Solution {public:    int removeDuplicates(int A[], int n) {	if(n<=0)		return 0;	int i=0,j=1;	while(j

转载地址:http://hqivl.baihongyu.com/

你可能感兴趣的文章
描述文件不匹配的解决方法
查看>>
springboot 配置文件
查看>>
省赛模拟一 阶乘除法
查看>>
两对象值合并
查看>>
C# 固定窗体大小且不能鼠标调整大小完美实现
查看>>
hdu 1856 More is better (并查集)
查看>>
javascript数据结构与算法--二叉树遍历(后序)
查看>>
Android Studio启动模拟器
查看>>
ORM 快速开发平台 -- WebAPI 配置实现
查看>>
PowerDesigner连接MySQL,建立逆向工程图解
查看>>
[Android] AndroidStudio + JNI(NDK)开发相关总结
查看>>
深圳短信猫厂家自带短信猫开发包支持多种开发语言
查看>>
基于python的WGS84转百度坐标
查看>>
生成器
查看>>
Hbase篇--HBase中一对多和多对多的表设计
查看>>
【java】构建工具,maven,ant,gradlew
查看>>
LintCode_14 二分查找
查看>>
04-python3.5-模拟三级菜单-省-县-区域--01
查看>>
算法竞赛入门经典chapter4:本章小结
查看>>
asp.net中的<%%>形式的详细用法实例讲解
查看>>