Python | Leetcode Python题解之第46题全排列

题目:

题解:

python 复制代码
class Solution:
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        def backtrack(first = 0):
            # 所有数都填完了
            if first == n:  
                res.append(nums[:])
            for i in range(first, n):
                # 动态维护数组
                nums[first], nums[i] = nums[i], nums[first]
                # 继续递归填下一个数
                backtrack(first + 1)
                # 撤销操作
                nums[first], nums[i] = nums[i], nums[first]
        
        n = len(nums)
        res = []
        backtrack()
        return res
相关推荐
hhzz17 小时前
智慧校园13类视频异常检测:数据集与预训练模型全攻略
人工智能·pytorch·python·深度学习·目标检测·机器学习
浩腾数字多媒体17 小时前
如何判断专业电子留言厂家适配条件?
大数据·人工智能·python
wabs66617 小时前
关于栈【力扣1047. 删除字符串中的所有相邻重复项的思考】
数据结构·c++·算法·leetcode··代码随想录
会编程的吕洞宾17 小时前
DeepAgents In Action学习(Third)
python·学习·django
'20617 小时前
**写了个自动整理下载视频的脚本:按片名归档、自动重命名、生成目录索引
开发语言·python·ffmpeg·音视频·cctv
码云数智-园园17 小时前
Python如何将律师的Excel噩梦变成自动化系统
python·自动化·excel
belldeep17 小时前
python:Selenium 4.47 编码新的写法
python·selenium
卷无止境17 小时前
除了开发api,FastAPI其实也可以配合jinja2模板写页面
后端·python·fastapi
OPEN-F17 小时前
Python进阶教程:项目工程化与虚拟环境
开发语言·python
OPEN-F18 小时前
Python进阶教程:自动化办公实战
python·c#·自动化