mycode  69.20%

class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
pos = 0
for i in range(1,len(nums)):
if nums[i] == nums[i-1]:
continue
pos += 1
nums[pos] = nums[i]
#print(pos,nums[pos],item,nums)
nums[:] = nums[:pos+1]
return pos + 1

参考:

思路和我的差不多,就是用一个标识符去记录重复项被非重复项覆盖的位置

def removeDuplicates(A):
if len(A) == 0:
return 0
j = 0
for i in range(0, len(A)):
if A[i] != A[j]:
A[i], A[j+1] = A[j+1], A[i]
j = j + 1
return j+1 removeDuplicates([0,0,1,1,1,4,5,6,6])

leetcode-easy-array-31 three sum的更多相关文章

  1. [LeetCode] Split Array with Equal Sum 分割数组成和相同的子数组

    Given an array with n integers, you need to find if there are triplets (i, j, k) which satisfies fol ...

  2. Leetcode: Split Array Largest Sum

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  3. [LeetCode] Split Array With Same Average 分割数组成相同平均值的小数组

    In a given integer array A, we must move every element of A to either list B or list C. (B and C ini ...

  4. [LeetCode] 325. Maximum Size Subarray Sum Equals k 和等于k的最长子数组

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  5. 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)

    转自  http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...

  6. C++ STL@ list 应用 (leetcode: Rotate Array)

    STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...

  7. [leetcode]364. Nested List Weight Sum II嵌套列表加权和II

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  8. Leetcode 931. Minimum falling path sum 最小下降路径和(动态规划)

    Leetcode 931. Minimum falling path sum 最小下降路径和(动态规划) 题目描述 已知一个正方形二维数组A,我们想找到一条最小下降路径的和 所谓下降路径是指,从一行到 ...

  9. LeetCode(113) Path Sum II

    题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...

  10. A. Array with Odd Sum Round #617(水题)

    A. Array with Odd Sum time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. C# System.Reflection (反射)

    在使用.NET创建的程序或组件时,元数据(metadata)和代码(code)都存储于“自成一体”的单元中,这个单元称为装配件.我们可以在程序运行期间访问这些信息. 在System.Reflectio ...

  2. File类的使用。

    在Java中,File是用来操作文件夹和文件的. 1.先来说说计算机中文件夹和文件的区别. 文件夹: 普通计算机文件夹是用来协助人们管理计算机文件的,每一个文件夹对应一块磁盘空间,它提供了指向对应空间 ...

  3. scipy.spatial.distance.cdist

    scipy.spatial.distance.cdist(XA, XB, metric='euclidean', p=2, V=None, VI=None, w=None)[source] Compu ...

  4. json字符串和json对象

    在对接口的时候,需要对某些地方进行字符串拼接的操作 现在我需要的是让图表中只默认显示前三条数据, 我的思路是先循环取出来三条外的公司名字 //声明前三个公司之外的公司数组 var selectcomp ...

  5. ERP和MES系统的区别和关系?

    1.ERP和MES的区别:ERP(Enterprise Resources Planning)是企业资源计划,它是在物料需求计划MRP(Material Requirement Planning)和制 ...

  6. redis、rabitmq对比

    redis.rabitmq对比 原文地址 简要介绍 RabbitMQ RabbitMQ是实现AMQP(高级消息队列协议)的消息中间件的一种,最初起源于金融系统,用于在分布式系统中存储转发消息,在易用性 ...

  7. 关于mysql的查询优化

    由于工作原因,最近甲方客户那边多次反应了他们那边的系统查询速度慢,经过排除之后,发现他们那边的数据库完全没有用到索引,简直坑得一笔,通过慢查询日志分析,为数据表建立了适当的索引之后,查询速度明显的提高 ...

  8. 点亮指路灯led

    为什么要使用LED? (bootloader,kernel)开发初期,由于串口等硬件尚未被初始化,因此调试手段相当有限,这时通常会采用LED来做为程序调试的重要手段. LED驱动设计: 1.设置GPI ...

  9. byteArray转换为double,int

    /*将int转为低字节在前,高字节在后的byte数组   b[0] = 11111111(0xff) & 01100001   b[1] = 11111111(0xff) & (n & ...

  10. Linux 学习 (一)

    最常用的7个Linux命令: cd:切换目录. pwd:查看当前所在目录. ls:查看目录下的文件. touch:没有文件则创建文件. mkdir:创建目录. mr:remove删除.         ...