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

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

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 nums = [1,1,2],

Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn’t matter what you leave beyond the new length.

没什么难度,此题主要注意节省空间。代码如下:

public class Solution {
public int removeDuplicates(int[] nums) { int length = 1; for(int i = 1; i < nums.length; i++) { if(nums[i] > nums[i - 1]) { nums[length++] = nums[i]; } } return length; }}

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

你可能感兴趣的文章
OpenCV暗通道去雾算法在内窥镜视频流中的应用
查看>>
OpenCV多曝光合成算法之熵值最大块合成
查看>>
导向滤波之图像融合(C++版) Image Fusion with Guided Filtering
查看>>
多曝光、多焦距图像合成(Opencv / C++)
查看>>
Opencv C++人脸识别
查看>>
OpenCV C++窗口滑动条插件
查看>>
创建ASCII数字打印机(OpenCV C++)
查看>>
快应用-容器组件-(官方示例代码运行后的 图示效果)一
查看>>
快应用-基础组件-(官方示例代码运行后的 图示效果)二
查看>>
快应用-表单组件-(官方示例代码运行后的 图示效果)三
查看>>
快应用-其他组件-(官方示例代码运行后的 图示效果)五
查看>>
快应用-扩展组件-(官方示例代码运行后的 图示效果)四
查看>>
js中 list的合并、list元素的移除添加、list元素的去重
查看>>
爬虫篇——自动化采集抖音热门视频数据
查看>>
快应用- 一套丰富完整的第三方组件库apex-ui
查看>>
快应用-实现添加购物车的动画效果
查看>>
快应用-Canvas实现尺子左右滑动的效果
查看>>
快应用-在快应用中接入友盟统计
查看>>
Java—将webp格式图片转为jpg或png (windows)
查看>>
快应用- 输入验证码精美效果的实现
查看>>