26. Remove Duplicates from Sorted Array
来源:互联网 发布:苏州网络测试招聘 编辑:程序博客网 时间:2024/06/07 19:25
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) { if(nums.length<=1){ return nums.length; } int len = 1; for(int i=1;i<nums.length;i++){ if(nums[i]!=nums[i-1]){ nums[len] = nums[i]; len++; } } return len; }}
0 0
- [LeetCode]26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- LeetCode 26. Remove Duplicates from Sorted Array
- LeetCode --- 26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- [Leetcode] 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 【leetcode】26. Remove Duplicates from Sorted Array
- 【leetcode】 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- [leetCode]26. Remove Duplicates from Sorted Array
- LeetCode 26.Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array LeetCode
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 26. Remove Duplicates from Sorted Array
- 线程池、函数指针、 pthread_cond_signal和pthread_cond_wait融合示例详解(附代码)
- python学习笔记7 迭代器
- Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on di
- MATLAB基础之矩阵相关的建立、基本操作
- oracle数据库的导出
- 26. Remove Duplicates from Sorted Array
- SICP 1.2.4 求幂
- 深度学习BP算法的推导(附加RNN,LSTM的推导说明)
- (C语言)顺序表之动态实现
- 27. Remove Element
- base64图片和字符串编解码详细过程
- windows下hiredis的编译
- MAP(Mean Average Precision):
- centos禁用防火墙