当前位置:网站首页>[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
边栏推荐
- ML&DL:机器学习和深度学习中超参数优化的简介、评估指标、过拟合现象、常用的调参优化方法之详细攻略
- A comprehensive understanding of gout: symptoms, risk factors, pathogenesis and management
- 漫谈Clickhouse Join
- Sqlserver gets the data of numbers, Chinese and characters in the string
- Some problems when SSH default port is not 22
- 1-14 express托管静态资源
- ca i啊几次哦啊句iu家哦
- 微服务链路风险分析
- Anaconda下安装Jupyter notebook
- 1-1 basic concepts of database
猜你喜欢

USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题

Pytorch quantitative practice (2)
测试媒资缓存问题

Introduce an online platform for multi omics integration and network visual analysis

Four Misunderstandings of Internet Marketing

布隆过滤器

PyTorch量化实践(1)

Akk bacteria - the next generation of beneficial bacteria

The Jenkins download Plug-in can't be downloaded. Solution

介绍一款|用于多组学整合和网络可视化分析的在线平台
随机推荐
FreeRTOS record (IX. an example of a bare metal project transferring to FreeRTOS)
1-16 路由的概念
模板方法模式介绍与示例
qsort函数和模拟实现qsort函数
1-11 创建线上文件服务
Three techniques for reducing debugging time of embedded software
1-15 nodemon
Develop your own package
兴奋神经递质——谷氨酸与大脑健康
Reading notes of Clickhouse principle analysis and Application Practice (1)
Reading notes of Clickhouse principle analysis and Application Practice (2)
Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
VIM common shortcut keys
jupyterbook 清空控制台输出
Ml & DL: introduction to hyperparametric optimization in machine learning and deep learning, evaluation index, over fitting phenomenon, and detailed introduction to commonly used parameter adjustment
Ssh server configuration file parameter permitrootlogin introduction
5G 在智慧医疗中的需求
[untitled]
. NETCORE redis geo type
jenkins下载插件下载不了,解决办法