26.RemoveDuplicatesfromSortedArray
来源:互联网 发布:网页抢购软件 编辑:程序博客网 时间:2024/04/30 00:37
Given a sorted array, remove the duplicates in place such that each element appear onlyonce 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 ofnums being1
and 2
respectively. It doesn't matter what you leave beyond the new length.
官方时间复杂度为O(n),空间复杂度为O(1)的算法如下:
public int removeDuplicates(int[] nums) { if (nums.length == 0) return 0; int i = 0; for (int j = 1; j < nums.length; j++) { if (nums[j] != nums[i]) { i++; nums[i] = nums[j]; } } return i + 1;}
阅读全文
0 0
- 26.RemoveDuplicatesfromSortedArray
- RemoveDuplicatesfromSortedArray
- leetcode26.RemoveDuplicatesfromSortedArray
- 26RemoveDuplicatesfromSortedArray
- LeetCode removeDuplicatesFromSortedArray两种解法方法
- 26. 连接器
- 26.nothing
- 26. Gnochive
- 26.SQLite
- 26.UIWindow
- 26.mkfifo
- OraCmd_1.7.2.26.rar
- 【面试】26.英语面试
- 26.左旋转字符串
- 26.左旋转字符串
- 26. 不要忽视错误!
- 26.数列特征
- 26.灯泡 (15分)
- 二叉树的深度优先遍历和广度优先遍历
- Android-Tips(实用Android开发技巧)
- C#接口调试
- 服务端TIME_WAIT解决
- Java筛选法求素数
- 26.RemoveDuplicatesfromSortedArray
- std::shared_ptr 与普通指针的转换
- 在java给别人邮箱发邮件
- 单元测试
- Java 执行系统命令
- 基础知识01
- 直接插入排序
- 快速排序--挖坑填数+分治法
- 一个评测指标就是MAP(Mean Average Precision)平均精度均值。