Remove Duplicates from Sorted Array
来源:互联网 发布:阿里云动易cms安装教程 编辑:程序博客网 时间:2024/06/14 04:35
英文题目
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 by modifying the input array in-place with O(1) extra memory.
中文题目
给定一个排好序的数组,去除其中重复的数字组成新的数组,返回新数组的长度,注意复杂度的问题
代码
class Solution { public int removeDuplicates(int[] nums) { if(nums.length == 0)return 0; int end = 1; int start = nums[0]; for(int i = 1; i < nums.length;i++){ if(nums[i] != start){ nums[end] = nums[i]; end++; start = nums[i]; } } return end; }}
更多文章
阅读全文
0 0
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates From Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- cssday1homework
- 一个简单的构造接口返回协议的工具类
- Vmware vSphere Client克隆虚拟机
- 微信小程序框架wepy.js父子组件双向通信
- std mutex
- Remove Duplicates from Sorted Array
- VB学习整理2 form 格式化
- C++进阶—>C++内存管理
- 30+关于如何成为更好Android开发者的短小而专业的建议
- dubbo 的构建
- PhpStorm2017版激活方法、汉化方法以及界面配置
- Sqoop的安装
- cssday2homework
- Understanding the JVM(九)虚拟机类加载的时机