Leetcode||47. Permutations II
来源:互联网 发布:wav音频分割软件 编辑:程序博客网 时间:2024/06/08 05:46
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,[1,1,2]
have the following unique permutations:
[ [1,1,2], [1,2,1], [2,1,1]]先排序,在深搜,深搜的时候用pre记录前一个数。
class Solution(object): def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ res = [] nums.sort() self.dfs(res, [], None, nums) return res def dfs(self, res, theList, pre, nums): if len(nums) == 0: res.append(list(theList)) pre = None for i in xrange(len(nums)): if nums[i] == pre: continue theList.append(nums[i]) self.dfs(res, theList, nums[i], nums[:i] + nums[i+1:]) theList.pop() pre = nums[i]
阅读全文
0 0
- [LeetCode]47.Permutations II
- LeetCode 47.Permutations II
- LeetCode --- 47. Permutations II
- [Leetcode] 47. Permutations II
- [leetcode] 47.Permutations II
- LeetCode 47. Permutations II
- 47. Permutations II LeetCode
- Leetcode 47. Permutations II
- LeetCode 47. Permutations II
- LeetCode - 47. Permutations II
- [LeetCode] 47. Permutations II
- leetcode 47. Permutations II
- [LeetCode]--47. Permutations II
- [LeetCode]--47. Permutations II
- [leetcode] 47. Permutations II
- leetcode 47. Permutations II
- Leetcode-47. Permutations II
- [LeetCode]--47. Permutations II
- JSP登录界面
- 掌柜大作战(5):使用AOP,统一记录方法执行所花的时间
- windows7下Python3.5.3 安装 matplotlib-2.1.0
- angularjs路由
- Http 协议
- Leetcode||47. Permutations II
- 第十八天 数组
- Android踩坑日记:FloatingActionButton的设置大小问题
- 安卓代码实现图片二次采样
- C语言学习笔记——C语言简介
- nginx+lua 限制接口访问次数
- Shadowsocks Python 服务器版一键安装脚本
- 弱校胡策 洛圣都(贪心)
- 51nod 1486 大大走格子【组合数学】【DP】