Permutations【python】
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】的更多相关文章
- 【Python②】python之首秀
第一个python程序 再次说明:后面所有代码均为Python 3.3.2版本(运行环境:Windows7)编写. 安装配置好python后,我们先来写第一个python程序.打开IDLE (P ...
- 【python】多进程锁multiprocess.Lock
[python]多进程锁multiprocess.Lock 2013-09-13 13:48 11613人阅读 评论(2) 收藏 举报 分类: Python(38) 同步的方法基本与多线程相同. ...
- 【python】SQLAlchemy
来源:廖雪峰 对比:[python]在python中调用mysql 注意连接数据库方式和数据操作方式! 今天发现了个处理数据库的好东西:SQLAlchemy 一般python处理mysql之类的数据库 ...
- 【python】getopt使用
来源:http://blog.chinaunix.net/uid-21566578-id-438233.html 注意对比:[python]argparse模块 作者:limodou版权所有limod ...
- 【Python】如何安装easy_install?
[Python]如何安装easy_install? http://jingyan.baidu.com/article/b907e627e78fe146e7891c25.html easy_instal ...
- 【Python】 零碎知识积累 II
[Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...
- 【Python】-NO.97.Note.2.Python -【Python 基本数据类型】
1.0.0 Summary Tittle:[Python]-NO.97.Note.2.Python -[Python 基本数据类型] Style:Python Series:Python Since: ...
- 【Python】-NO.99.Note.4.Python -【Python3 条件语句 循环语句】
1.0.0 Summary Tittle:[Python]-NO.99.Note.4.Python -[Python3 条件语句 循环语句] Style:Python Series:Python Si ...
- 【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 ...
随机推荐
- python利用utf-8编码判断中文英文字符(转)
下面这个小工具包含了判断unicode是否是汉字.数字.英文或者其他字符,全角符号转半角符号,unicode字符串归一化等工作. #!/usr/bin/env python # -*- coding: ...
- 道路软件质量:SourceMonitor
有些事情必须这样做,不是幸福,但是,缓解疼痛,因为不.更痛苦--这是无奈. 夏中义 <文心独白> 1 简介 博客没有更新了一段时间,了阿里上市的成功之处:选择和坚持.事实上人生并没有绝对的 ...
- JQuery的JSTree使用
这是一个树形菜单的展示.其功能及其强大,几乎可以提供你对树结构的各种要求.下面,对其简述. 首先,感谢 Ivan Bozhanov利用JQuery对该组件的开发.同时还要感谢我的技术总监Mr. ...
- EF使用时异常:对一个或多个实体的验证失败。有关详细信息
//最顶级异常中是不提示具体哪个字段验证失败,必须到详细异常类型中查看 try { //EF操作 } catch (System.Data.Entity.Validation.DbEntityVali ...
- 学习:WordXML格式初步分析
Office2003以上,Word可以以XML文本格式存储,这样就可以使用外部程序创建Word文件,而不需要使用Word的对象.也能够自由的打开分析Word文件,或者发布到自己的Web页面,或者其他更 ...
- wget 无法下载jdk的处理办法
完整语句:wget --no-cookie --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle. ...
- PHP学习笔记13-操作Cookie
PHP会话管理图: 创建index.php: <?php /** * Created by PhpStorm. * User: Administrator * Date: 2015/7/1 * ...
- jmeter 压力测试 参数
Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告中的各项数据表示什么意思,顺便在这里公布一下,以备大家查阅. 如果 ...
- vim插件管理之Vundle
Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性.正是由于其可定制的特性, 许许多多的Vim插件便诞生了.管理这些插件又成为我们最为头疼的问题,最近无 ...
- struts OGNL数据标签
OGNL对象图导航语言,类似于el表达式,strut的底层就是用这个写的在导入struts-core的时候会导入ognl.jar public class Test { public static v ...