当前位置:网站首页>[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
边栏推荐
- Pytorch quantitative practice (2)
- Oprator-1 first acquaintance with oprator
- 程序员女友给我做了一个疲劳驾驶检测
- 微服务链路风险分析
- Open the jupyter notebook/lab and FAQ & settings on the remote server with the local browser
- 《Dynamic Routing Between Capsules》论文学习总结
- ca i啊几次哦啊句iu家哦
- Auto-created primary key used when not defining a primary key
- 京东与腾讯续签三年战略合作协议;起薪涨至26万元,韩国三星SK争相加薪留住半导体人才;Firefox 102 发布|极客头条
- 1-1 basic concepts of database
猜你喜欢

Arcmap|assign values to different categories of IDS with the field calculator

PyTorch量化实践(2)

Usbcan analyzer's supporting can and canfd comprehensive test software lkmaster software solves engineers' can bus test problems

布隆过滤器

Jupyter notebook/lab switch CONDA environment

Clickhouse native monitoring item, system table description

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

根据肠道微生物组重新思考健康饮食

Excitatory neurotransmitter glutamate and brain health

看阿里云 CIPU 的 10 大能力
随机推荐
Testing media cache
Understand what MySQL index push down (ICP) is in one article
Jupyterbook clear console output
“信任机器”为发展赋能
[untitled]
1-15 nodemon
Bloom filter
1-11 创建线上文件服务
Fletter nested hell? No, constraintlayout to save!
《ClickHouse原理解析与应用实践》读书笔记(2)
Excitatory neurotransmitter glutamate and brain health
1-2 install and configure MySQL related software
ClickHouse distributed表引擎
PyTorch量化感知训练(QAT)步骤
攻防演练中的防泄露全家福
Upgrade Kube with unknown flag: --network plugin
【无标题】第一次参加csdn活动
Open the jupyter notebook/lab and FAQ & settings on the remote server with the local browser
看阿里云 CIPU 的 10 大能力
Introduction and example of template method mode