# -*- coding: utf8 -*-
'''
__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array
https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/ 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 A = [1,1,2],
Your function should return length = 2, and A is now [1,2]. ===Comments by Dabay===
一次循环,两个指针,一个指向最后插入的位置,另外一个一直往前面走。
如果两个指针的数一样,二号指针继续走。
如果不一样,把二号指针指向的数插入到一号指针的后面。
最后跟新数组,返回长度。
''' class Solution:
# @param a list of integers
# @return an integer
def removeDuplicates(self, A):
i,j = 0,0
while j < len(A):
if A[i] != A[j]:
i += 1
A[i] = A[j]
j += 1
A = A[:i+1]
return len(A) def main():
sol = Solution()
print sol.removeDuplicates([1,1,2]) if __name__ == "__main__":
import time
start = time.clock()
main()
print "%s sec" % (time.clock() - start)

[Leetcode][Python]26: Remove Duplicates from Sorted Array的更多相关文章

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

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

    @requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...

  3. 【LeetCode】26. Remove Duplicates from Sorted Array 解题报告(Python&C++&Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https:// ...

  4. 【LeetCode】26. Remove Duplicates from Sorted Array

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  5. 【一天一道LeetCode】#26. Remove Duplicates from Sorted Array

    一天一道LeetCode系列 (一)题目 Given a sorted array, remove the duplicates in place such that each element app ...

  6. LeetCode OJ 26. Remove Duplicates from Sorted Array

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  7. Leetcode No.26 Remove Duplicates from Sorted Array(c++实现)

    1. 题目 1.1 英文题目 Given an integer array nums sorted in non-decreasing order, remove the duplicates in- ...

  8. LeetCode:26. Remove Duplicates from Sorted Array(Easy)

    1. 原题链接 https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/ 2. 题目要求 给定一个已 ...

  9. 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Follow ...

随机推荐

  1. sass颜色

    1只定义一次颜色 {优点:可以给变量赋予不同的值: {缺点:变量名称更改与变量值混乱: 2变浅加深 /*颜色函数*/ .warning-box { background-color:lighten($ ...

  2. LINQ 联合查询

    List<Attachment> imgList = (from a in ZQSDWEBEntities.Attachment                               ...

  3. linux----ln

    1.格式 ln source_file_path target_file_path 2.执行ln 命令的用户要对source_file_path有写权限,才可以创建软连接. 3.souce_file这 ...

  4. jQuery validate (转载)

    转自:http://blog.sina.com.cn/s/blog_608475eb0100h3h1.html jQuery校验 官网地址:http://bassistance.de/jquery-p ...

  5. KDE子项目一览 good

    https://www.kde.org/applications/development/ https://www.kde.org/applications/graphics/ https://www ...

  6. 打开网页自动弹出QQ临时会话 (打开网站弹出QQ聊天) qq.js文件代

    eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35 ...

  7. cnn softmax regression bp求导

    内容来自ufldl,代码参考自tornadomeet的cnnCost.m 1.Forward Propagation convolvedFeatures = cnnConvolve(filterDim ...

  8. opensatck 使用devstack在 laptop上的 网络配置

    http://docs.openstack.org/developer/devstack/guides/neutron.html Physical Network Setup In most case ...

  9. Windows系统的线程调度与软件中断分发

    在Windows操作系统内核把软件中断分为三个中断级别:DISPATCH_LEVEL,APC_LEVEL,PASSVIE_LEVEL.同时他们与线程的调试相关,WINDOWS内核中没有一个专门的程序来 ...

  10. iOS7.0中UILabel高度调整注意事项(转)

    注释:原文链接丢失. 我的“记词助手”在升级到iOS7之后,一直出现UILabel错位的问题: 我的label是用- (CGSize)sizeWithFont:(UIFont *)font const ...