Leetcode: Permutations II
2015-09-09 07:37
330 查看
Question
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], and [2,1,1].
Show Tags
Show Similar Problems
Solution
[code]class Solution(object): def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ res = [] if nums==[] or len(nums)==0: return res nums.sort() self.helper(nums, [], res) return res def helper(self, lst, item, res): if lst==[]: res.append(item) return for ind,elem in enumerate(lst): if ind>0 and lst[ind]==lst[ind-1]: continue temp = lst[:] del temp[ind] self.helper(temp, item+[elem], res)
相关文章推荐
- 游戏人工智能开发之6种决策方法
- listview 精确定位
- Inter-App Communication
- Leetcode: Combination Sum III
- java自带线程池和队列详细讲解
- Fedora 22中的用户和用户组管理
- Lintcode - Max points on a line
- 甲骨文解雇Java技术讲师:放弃的节奏?
- Leetcode: Combination Sum II
- OSChina 周三乱弹 —— 啪啪啪是敲键盘的声音
- 两分钟彻底让你明白Android Activity生命周期(图文)!
- iOS8 自定义UITabBar (使用popToViewController导致的UITabBarButton重叠的问题)
- 给新程序员的10条建议
- How to use Session attributes in Spring-mvc
- gradle--第六章、基本构建脚本3
- Leetcode: Combination Sum
- Leet Code 8 String to Integer (atoi)
- js获取浏览器滚动条距离顶端的距离
- Leetcode Implement Stack using Queues
- powershell的一个小游戏,看看能写几种方式出来