国外的表达思维跟咱们有很大差别,做这道题的时候很明显。简单说本题就是让你把有序数组中的重复项给换成正常有序的。比如 1 2 2 3换成 1 2 3 3,根本不需要考虑重复的怎么办,怎么删除重复项等等。拿起键盘干就行了。然后返回有序项的下标就可以。

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.

给定一个排序的数组,删除重复的位置,使每个元素只显示一次并返回新的长度。

不要为另一个数组分配额外的空间,您必须使用常量内存来执行此操作。

例如,
给定输入数组nums = [1,1,2],

你的函数应该返回length = 2,num的前两个元素分别为1和2。 无论你离开新的长度什么都不重要。

 class Solution {
public int removeDuplicates(int[] nums) {
int count=1;
for(int i=1;i<nums.length;i++){
if(nums[i]!=nums[i-1]){
nums[count]=nums[i]; //将多余重复项换成正常有序项
count++;
}
}
return count;
}
}

LeetCode记录之26——Remove Duplicates from Sorted Array的更多相关文章

  1. leetCode练题——26. Remove Duplicates from Sorted Array

    1.题目 26. Remove Duplicates from Sorted Array--Easy Given a sorted array nums, remove the duplicates  ...

  2. 【leetcode❤python】26. Remove Duplicates from Sorted Array

    #-*- coding: UTF-8 -*-class Solution(object):    def removeDuplicates(self, nums):        "&quo ...

  3. [Leetcode][Python]26: Remove Duplicates from Sorted Array

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...

  4. LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++>

    LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...

  5. 26. Remove Duplicates from Sorted Array【easy】

    26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...

  6. [LeetCode] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...

  7. [LeetCode] 26. Remove Duplicates from Sorted Array ☆(从有序数组中删除重复项)

    [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项 描述 Given a sorted array nums, remove the d ...

  8. 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 ...

  9. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法

    Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...

随机推荐

  1. 介绍个好点的,JAVA技术群

    java技术交流,意义是以QQ群为媒介,添加一些有多年工作经验和技术的人群,为有问题的人群解答在工作中遇到的各种问题为思想,java技术交流群号161571685,创建时间为2010年,走过将近5年的 ...

  2. PhoneGap 3.4 开发配置及问题

    PhoneGap这个坑爹货,开发确实迅速,又无需学习新知识,但又有N多深不见底坑,最大的坑无疑是性能,滑动时卡顿明显,iPhone5上性能比较好,大部分安卓上就坑爹了,神马动画效果最好少用:其次是不同 ...

  3. Java c3p0 连接 MySQL

    <?xml version="1.0" encoding="UTF-8"?> <!-- 需要导入c3p0驱动jar包和mysql驱动jar包 ...

  4. lucene 第一天

    Lucene/Solr   第一天 1. 课程计划 Lucene介绍 全文检索流程介绍 a) 索引流程 b) 搜索流程 Lucene入门程序 a) 索引实现 b) 搜索实现 分词器 a) 分词介绍 b ...

  5. HighCharts SVN IReport进行PDF报表设计--模板

    BOS物流项目笔记第十五天 HIghcharts是很强大的图表绘制插件,它是基于纯js绘制的.当然地,对于图表也会有很多操作了.下面就我工作时遇到的一些比较常见的highcharts的操作进行小结,不 ...

  6. 怎样使用Mock Server

    转载自:http://www.cnblogs.com/111testing/p/6091460.html 怎样使用Mock Server   一,去这里https://github.com/dream ...

  7. jQuery 演变史

    一.说明 最近我读完了 jQuery 官方的博客仓库,目的是为了梳理清楚 jQuery API 接口的演变过程.从而明确知道在对应版本下使用正确.合适的 API,以下便是我的总结笔记. jQuery ...

  8. [GO]局部变量的特点

    package main import "fmt" func main() { //定义在{}里的变量就是局部变量,只能在{}里起作用 //作用域,变量起作用的范围 //执行到定义 ...

  9. Terminologies in MVC: Part 2 (Razor Engine Syntax vs Web Form)

    By Abhishek Jaiswal :) on Mar 21, 2015 In this article we learn about Razor Engine Syntax vs Web For ...

  10. 编写高质量代码改善C#程序的157个建议——建议50:在Dispose模式中应区别对待托管资源和非托管资源

    建议50:在Dispose模式中应区别对待托管资源和非托管资源 真正资源释放代码的那个虚方法是带一个bool参数的,带这个参数,是因为我们在资源释放时要区别对待托管资源和非托管资源. 提供给调用者调用 ...