当前位置:网站首页>[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
边栏推荐
- Arcmap|assign values to different categories of IDS with the field calculator
- VIM common shortcut keys
- 你我他是谁
- 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
- qsort函数和模拟实现qsort函数
- Encryption and decryption and the application of OpenSSL
- ca i啊几次哦啊句iu家哦11111
- 1-12 初步认识Express
- jupyter notebook/lab 切换conda环境
- 【回溯】全排列 leetcode46
猜你喜欢

《ClickHouse原理解析与应用实践》读书笔记(3)
一文读懂什么是MySQL索引下推(ICP)

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

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

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

Clickhouse native monitoring item, system table description

Open the jupyter notebook/lab and FAQ & settings on the remote server with the local browser

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

Four Misunderstandings of Internet Marketing

Pytorch quantitative practice (2)
随机推荐
Anaconda下安装Jupyter notebook
Nacos部署及使用
Fletter nested hell? No, constraintlayout to save!
clickhouse原生監控項,系統錶描述
ca i啊几次哦啊句iu家哦11111
clickhouse原生监控项,系统表描述
Auto-created primary key used when not defining a primary key
Upgrade Kube with unknown flag: --network plugin
1-3 使用SQL管理数据库
给苏丹国安德森苏丹的撒过 d s g
Jupyter notebook/lab switch CONDA environment
激发新动能 多地发力数字经济
AKK菌——下一代有益菌
Export El table as is to excel table
The 16th Heilongjiang Provincial Collegiate Programming Contest
《ClickHouse原理解析与应用实践》读书笔记(2)
1-15 nodemon
Rethink healthy diet based on intestinal microbiome
jenkins下载插件下载不了,解决办法
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