当前位置:网站首页>[backtracking] full arrangement II leetcode47
[backtracking] full arrangement II leetcode47
2022-06-30 21:46:00 【Breeze_】
Given a sequence that can contain repeating numbers nums , In any order Returns all non repeating permutations . Example 1: Input :nums = [1,1,2] Output :
[[1,1,2], [1,2,1], [2,1,1]] Example 2: Input :nums = [1,2,3]
Output :[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
link :https://leetcode.cn/problems/permutations-ii
Ideas : and lc46 What's different is , Contains duplicate numbers , here , Learn from array sum II The idea of , First, let's talk about sequence sorting , Then every time you traverse for Loop to determine whether the next number is the same as the previous one , Same auto ignore ( prune ) fall , So as to achieve the goal of weight removal
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
self.ret = []
'''NOTE 1. Thinking about recursive trees ( What are the root and intermediate nodes ) 2. Think about each state of the recursive tree (for The loop condition ) 3. Think about the variables of the recursive tree ( Formal parameters of the backtrace function ) 4. Think about what the leaf nodes of a recursive tree are ( Where to end return And save what ) '''
def helper(nums:list,his:list):
if len(nums)==0:
self.ret.append(his)
return
for idx in range(len(nums)):
if idx!=0 and nums[idx]==nums[idx-1]: # Weight removal tips
continue
helper(nums[:idx]+nums[idx+1:],his+[nums[idx]])
nums.sort()
helper(nums,[])
return self.ret
边栏推荐
- 1-1 数据库的基本概念
- Coefficient of variation method matlab code [easy to understand]
- The 16th Heilongjiang Provincial Collegiate Programming Contest
- Jupyter notebook/lab switch CONDA environment
- 给苏丹国安德森苏丹的撒过 d s g
- 将el-table原样导出为excel表格
- 1-21 JSONP接口
- pytorch geometric torch-scatter和torch-sparse安装报错问题解决
- 根据肠道微生物组重新思考健康饮食
- 1-12 初步认识Express
猜你喜欢

It is urgent for enterprises to protect API security

Reading notes of Clickhouse principle analysis and Application Practice (3)

《Dynamic Routing Between Capsules》论文学习总结

asp. Net core JWT delivery

clickhouse原生监控项,系统表描述

Four Misunderstandings of Internet Marketing

布隆过滤器

PyTorch量化实践(1)

Akk bacteria - the next generation of beneficial bacteria

Troubleshooting the problem of pytorch geometric torch scatter and torch spark installation errors
随机推荐
Arcmap|assign values to different categories of IDS with the field calculator
Jupyterbook clear console output
USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题
Excitatory neurotransmitter glutamate and brain health
1-12 preliminary understanding of Express
1-20 预检请求
1-1 basic concepts of database
CA I ah, how many times Oh, ah sentence IU home Oh 11111
Prediction and regression of stacking integrated model
Coefficient of variation method matlab code [easy to understand]
Clickhouse distributed table engine
Document Layout Analysis: A Comprehensive Survey 2019论文学习总结
1-2 install and configure MySQL related software
Bloom filter
1-11 创建线上文件服务
1-21 JSONP接口
jenkins下载插件下载不了,解决办法
本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置
“信任机器”为发展赋能
Clickhouse Native Monitoring item, System table Description