leetcode-easy-array-31 three sum
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的更多相关文章
- [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 ...
- Leetcode: Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- [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 ...
- [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 ...
- 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)
转自 http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...
- C++ STL@ list 应用 (leetcode: Rotate Array)
STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...
- [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. ...
- Leetcode 931. Minimum falling path sum 最小下降路径和(动态规划)
Leetcode 931. Minimum falling path sum 最小下降路径和(动态规划) 题目描述 已知一个正方形二维数组A,我们想找到一条最小下降路径的和 所谓下降路径是指,从一行到 ...
- 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 ...
- 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 ...
随机推荐
- android中的rn项目更新gradle及补充二
修改build.gradle的版本,com.android.tools.build:gradle:2.1.0, 改为更高的,然后更改gradle/wrapper/gradle-wrapper.prop ...
- inux下:热插拔和模块是什么
一.何为模块? 文件系统.设备驱动程序.网络协议都可以理解为模块.模块本质也是普通的软件系统. 二.热插拔 硬件层面:只在不断电.不关闭系统的情况下增加或者删除对应部件,比如电源.硬盘.一些高端设备硬 ...
- Nagios监控系统部署(源码)(四)
Nagios监控系统部署(源码) 1. 概述2. 部署Nagios2.1 创建Nagios用户组2.2 下载Nagios和Nagios-plugin源码2.3 编译安装3. 部署Nagios-pl ...
- 22_4mybatis——动态SQL
1.创建maven工程并导入坐标 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE confi ...
- (转) windows 下ORA-12514:TNS 监听问题
在使用Orcale数据库的时候不知道各位是否遇到过如图的监听问题(或者显示类似的问题),以下方法就是来解决这样的问题的. 首先右击计算机,选择管理.选择左侧栏的服务与应用程序,右侧栏选服务. ...
- 找不到javax.
https://blog.csdn.net/q343509740/article/details/79515911 idea导入java工程 file --> new -->存在的工程
- canvas在高倍屏下变模糊的处理办法
因为canvas不是矢量图,而是像图片一样是位图模式的.如果不做Retina屏适配的话,例如二倍屏,浏览器就会以2个像素点的宽度来渲染一个像素,该canvas在Retina屏幕下相当于占据了2倍的空间 ...
- rsyncd.conf配置文件
rsyncd.conf配置文件 #Rsync server#created by oldboy 15:01 2009-6-5##rsyncd.conf start##uid = rootgid ...
- python出现SyntaxError: Non-ASCII character '\xe6' in file \的错误
出现这个问题的主要原因是因为python2的编码是ASCII码,文件中有中文的话就得使用utf8编码,只需要在文件的头部加上以下其中一种标注: 一.在文件头部添加如下注释码: # coding=< ...
- HDU-4185-Oil Skimming(最大匹配)
链接: https://vjudge.net/problem/HDU-4185 题意: Thanks to a certain "green" resources company, ...