class Solution(object):
def fourSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[List[int]]
"""
numLen=len(nums)
if numLen <= 3:
return list()
nums.sort()
res,d=set(),{}
for p in xrange(numLen):
q=p+1
while q < numLen:
if nums[p]+nums[q] not in d:
d[nums[p]+nums[q]] = [(p,q)]
else:
d[nums[p]+nums[q]].append((p,q))
q+=1
for i in xrange(numLen):
j=i+1
while j < numLen-2:
tmp = target-nums[i]-nums[j]
if tmp in d:
for k in d[tmp]:
if k[0] > j:
res.add( ( nums[i], nums[j], nums[k[0]], nums[k[1]] ) )
j+=1
return [list(i) for i in res]

@link http://chaoren.is-programmer.com/posts/45308.html

leetcode 4sum python的更多相关文章

  1. LeetCode专题-Python实现之第28题: Implement strStr()

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  2. LeetCode专题-Python实现之第27题:Remove Element

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  3. LeetCode专题-Python实现之第26题:Remove Duplicates from Sorted Array

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  4. LeetCode专题-Python实现之第21题:Merge Two Sorted Lists

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  5. LeetCode专题-Python实现之第20题:Valid Parentheses

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  6. LeetCode专题-Python实现之第9题:Palindrome Number

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  7. LeetCode专题-Python实现之第14题:Longest Common Prefix

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  8. LeetCode专题-Python实现之第13题:Roman to Integer

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  9. LeetCode专题-Python实现之第7题:Reverse Integer

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

随机推荐

  1. 依赖注入及AOP简述(六)——字符串请求模式 .

    2.     依赖注入对象的请求模式 前一节我们讨论了关于声明注入点的几种方法,这一节主要来介绍在注入点上如何定位到所需要的标识符的话题.基本上,我们可以用字符串为标识符来请求依赖对象.或者用全类名( ...

  2. HTML2列表表单框架

    HTML——Hyper Text Markup Language <html>,<head>,<body> 一.基本标签: (一)格式标签:——模型:word工具栏 ...

  3. C# 过滤特殊字符

    . /// <summary> /// 过滤不安全的字符串 /// </summary> /// <param name="Str"></ ...

  4. PHP zip压缩文件及解压

    PHP zip压缩文件及解压 利用ZipArchive 类实现 只有有函数.界面大家自己写 ZipArchive(PHP 5.3 + 已自带不需要安装dll) /** * 文件解压 * @param ...

  5. 获取ajax对象

    function ajaxFunction(){ var xmlHttp; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest ...

  6. AsyncTask 不能与Thread.sleep()同时使用解决方案

    public class MainActivity extends Activity { private ImageView iv_ads; String urrstrString = "h ...

  7. 预定义异常 - PHP手册笔记

    Exception是所有异常的基类,类摘要如下: <?php class Exception { protected string $message; // 异常消息内容 protected i ...

  8. centos下python的pymssql模块安装及简单使用

    1.安装pymssq模块 1-1.环境准备: 1-1-1.unixODBC安装 yum install unixODBC unixODBC-devel -y 1-1-2.freetds安装 下载 fr ...

  9. svn检出maven工程到eclipse里面,部署到tomcat的步骤

    1. 首先import project from svn 2.检出项目后,如果是多模块的maven项目,在子模块右击,import as project 3.右击项目,properties->d ...

  10. Three.js基础

    Three.js基础探寻一 Three.js基础探寻一   1.webGL 一种网络标准,定义了一些较底层的图形接口. 2.Three.js 一个3Djs库,webGL开源框架中比较优秀的一个.除了w ...