class Solution:
# @param num, a list of integer
# @return a list of lists of integers
def permute(self, num):
length=len(num)
if length==1:
return [num]
else:
res=[]
for i in range(length):
d=self.permute(num[0:i]+num[i+1:length])
for j in d:
res.append(j+[num[i]])
#去除重复项
k=len(res)-1
while k>0:
for j in range(k):
if self.IsSameList(res[j], res[k]):
del res[k]
break
k-=1
return res def IsSameList(self,A,B):
an=len(A)
bn=len(B)
if (an!=bn):
return False
else:
for i in range(an):
if (A[i]!=B[i]):
return False
return True if __name__=='__main__':
num=[1,2,3]
s=Solution()
print(s.permute([1,1,3]))

C++的版本:http://hi.baidu.com/li_iois/item/4e093bda9b9bc22039f6f7aa(以前写的)

Permutations【python】的更多相关文章

  1. 【Python②】python之首秀

       第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...

  2. 【python】多进程锁multiprocess.Lock

    [python]多进程锁multiprocess.Lock 2013-09-13 13:48 11613人阅读 评论(2) 收藏 举报  分类: Python(38)  同步的方法基本与多线程相同. ...

  3. 【python】SQLAlchemy

    来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...

  4. 【python】getopt使用

    来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...

  5. 【Python】如何安装easy_install?

    [Python]如何安装easy_install? http://jingyan.baidu.com/article/b907e627e78fe146e7891c25.html easy_instal ...

  6. 【Python】 零碎知识积累 II

    [Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...

  7. 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】

    1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...

  8. 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】

    1.0.0 Summary Tittle:[Python]-NO.99.Note.4.Python -[Python3 条件语句 循环语句] Style:Python Series:Python Si ...

  9. 【Python】-NO.98.Note.3.Python -【Python3 解释器、运算符】

    1.0.0 Summary Tittle:[Python]-NO.98.Note.3.Python -[Python3 解释器] Style:Python Series:Python Since:20 ...

随机推荐

  1. servlet response 中文乱码

    先,response返回有两种,一种是字节流outputstream,一种是字符流printwrite. 申明:这里为了方便起见,所有输出都统一用UTF-8编码. 先说字节流,要输出“中国" ...

  2. Ext JS学习第五天 Ext_window组件(二)

    此文用来记录学习笔记 •上一讲我们已经学过了window的使用,那么在这将中,我们将结合然后把Ext中需要注意的地方,以及组建的使用给予介绍.indow做几个Web开发的经典示例. •ExtWeb实战 ...

  3. [小知识点]IE6下不支持:hover的解决方法

    在网上百度到的解决办法,感觉不错,和大家分享一下. 在CSS样式里加一句代码"body{behavior:url("文件夹/csshover.htc");}"即 ...

  4. js div 内容显示分页

    由于工作需要 div固定大小 而内容不定 所以 如果内容过多自然就显示不出来了 所以 需要分页一类的功能下面是代码 <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  5. jquery-1.10.2.min.js之Multiple markers at this line

    1.windows-preferences  输入validation 2. 点击进入  3. 将JavaScript validator for js files 的两个对勾去了就OK!     4 ...

  6. DDB与DIB的区别

    DDB(设备相关位图) DDB依赖于具体设备:DDB的颜色模式必需与输出设备相一致.例如,如果当前的显示设备是256色模式,那么DDB必然也是256色的.在256色以下的位图中存储的像素值是系统调色板 ...

  7. C++动态数组的实现

    #include <iostream> using namespace std; int main() { int n; while(cin>>n) { ]; p[]=; p[ ...

  8. iOS_第3方类库_BlurAlertView_GPUImage

    最终效果图: 先加入GPUImage.framework 导入BlurAlertView的类声明和类实现 // // BlurAlertView.h // 特效弹出框 // // Created by ...

  9. Failed to load the JNI shared library

    解决Eclipse无法打开"Failed to load the JNI shared library" 这是由于JDK配置错误所导致的现象. 一般说来,新购笔记本会预装64位的w ...

  10. 用AS3清空容器下所有子显示对象

    容器中的子显示对象分为两类: 处于显示列表中的子显示对象.被numChildren所记录的. 由容器graphics对象绘制出来的矢量图.这个矢量图不属于Shape类型,不在容器的显示列表中,不被nu ...