当前位置:网站首页>[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
边栏推荐
- A comprehensive understanding of gout: symptoms, risk factors, pathogenesis and management
- 1-21 jsonp interface
- How to run jenkins build, in multiple servers with ssh-key
- 《ClickHouse原理解析与应用实践》读书笔记(1)
- 用yml文件进行conda迁移环境时的报错小结
- 给苏丹国安德森苏丹的撒过 d s g
- Sqlserver string type converted to decimal or integer type
- Ssh server configuration file parameter permitrootlogin introduction
- 看阿里云 CIPU 的 10 大能力
- Sqlserver gets the data of numbers, Chinese and characters in the string
猜你喜欢

Four Misunderstandings of Internet Marketing

Dm8: generate DM AWR Report

Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test

興奮神經遞質——穀氨酸與大腦健康

看阿里云 CIPU 的 10 大能力

本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置

《ClickHouse原理解析与应用实践》读书笔记(1)

程序员女友给我做了一个疲劳驾驶检测

clickhouse原生監控項,系統錶描述

Markdown notes concise tutorial
随机推荐
Coefficient of variation method matlab code [easy to understand]
It is urgent for enterprises to protect API security
. NETCORE redis geo type
ca i啊几次哦啊句iu家哦
1-15 nodemon
Reading notes of Clickhouse principle analysis and Application Practice (1)
介绍一款|用于多组学整合和网络可视化分析的在线平台
1-15 nodemon
将el-table原样导出为excel表格
【无标题】
侧睡哈哈哈哈
《Dynamic Routing Between Capsules》论文学习总结
.netcore redis GEO类型
程序员女友给我做了一个疲劳驾驶检测
1-3 使用SQL管理数据库
Installing jupyter notebook under Anaconda
How to run jenkins build, in multiple servers with ssh-key
Export El table as is to excel table
全面认识痛风:症状、风险因素、发病机理及管理
Document Layout Analysis: A Comprehensive Survey 2019论文学习总结