Array - RemoveDuplicatesfromSortedArray
/**
* 无额外空间,只要前n个是不重复的就行,不需要修改后面的数字
* @param nums 已排序的数组
* @return 去除重复数字后的长度
*/
public int removeDuplicates(int[] nums) {
if(nums == null || nums.length == 0) {
return 0;
} else if(nums.length == 1) {
return 1;
}
// 使用两个指针
int j = 0;
for(int i = 1; i < nums.length; i++) {
if(nums[j] != nums[i]) {
j++;
nums[j] = nums[i];
}
}
return ++j;
}
Array - RemoveDuplicatesfromSortedArray的更多相关文章
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- No.026:Remove Duplicates from Sorted Array
问题: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- [Leetcode][Python]26: Remove Duplicates from Sorted Array
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...
- leetcode — remove-duplicates-from-sorted-array
import java.util.Arrays; /** * Source : https://oj.leetcode.com/problems/remove-duplicates-from-sort ...
- Integer Array Ladder questions
1.这个题不难,关键在于把题目意思理解好了.这个题问的不清楚.要求return new length,很容易晕掉.其实就是return 有多少个单独的数. import java.util.Array ...
- LeetCode--1、26、27、35、53 Array(Easy)
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to ...
- C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array
26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...
- 【Remove Duplicates from Sorted Array】cpp
题目: https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Given a sorted array, remove ...
- 【leetcode】 26. Remove Duplicates from Sorted Array
@requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...
随机推荐
- SAP ECC6 IDES安装及虚拟机下载
SAP ECC6.0 SR3 IDES Oracle.torrent(48.12G)下载 SAP ECC6 安装系列 SAP ECC6.0 IDES在Win7 X64上的安装 SAP ECC6.0 R ...
- Ubuntu 14.04中修复默认启用HDMI后没有声音的问题
声音问题在Ubuntu中是老生常谈了.先前我已经在修复Ubuntu中的“无声”问题一文中写到了多种方法,但是我在此正要谈及的声音问题跟在另外一篇文章中提到的有所不同. 因此,我安装了Ubuntu 14 ...
- UIButton和UINavigationItem设置图片和文字位置
1.UIButton设置文字位置 有些时候我们想让UIButton的title居左对齐,我们设置 btn.textLabel.textAlignment = UITextAlignmentLeft 是 ...
- DSOFramer控件使用注意事项
1.引用dll==>AxInterop.DSOFramer.dll ==>Interop.DSOFramer.dll ==>WindowsFormsIntegration ==> ...
- 19个很有用的 JavaScript库推荐
流行的 JavaScript 库有jQuery,MooTools,Prototype,Dojo和YUI等,这些 JavaScript 库功能丰富,加上它们众多的插件,几乎能实现任何你需要的功能 然而需 ...
- 集成Python Shell
每次启动shell会话都要导入Python相关对象(数据库实例和模型),这是件十分枯燥的工作.为了避免一直重复导入,我们可以做些配置,让flask-script的shell命令自动导入特定的对象. F ...
- QMYSQL driver not loaded 的原理和解决办法
转:http://blog.csdn.net/m15814478834/article/details/49902077 最近使用Qt遇到了"QMYSQL driver not loaded ...
- 352. Data Stream as Disjoint Intervals (TreeMap, lambda, heapq)
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- unity3d四元数和旋转矩阵
http://blog.csdn.net/kfqcome/article/details/10729551 一 四元数 Quaternion中存放了x,y,z,w四个数据成员,可以用下标来进行访问,对 ...
- jquery 插件的实现和优化
1.menus 实现: $.fn.menu=function(options){ var $this=$(this); var cross='<div class="zhiniu_cr ...