当前位置:网站首页>previous permutation lintcode51
previous permutation lintcode51
2022-07-03 11:52:00 【Just change your name】
TLE edition
This version cannot pass . Just for myself to deepen dfs The understanding of the .
Time complexity O(N^N), For every position , It's all traversal n Time , Yes n A place .
from typing import (
List,
)
class Solution:
"""
@param nums: A list of integers
@return: A list of integers that's previous permuation
"""
def dfs(self, nums, query, sub_ans, per_lst, visited):
if query == sub_ans:
return True
if len(sub_ans) == len(nums):
per_lst.append(sub_ans[:])
# print(per_lst)
return False
for i in range(len(nums)):
if i not in visited:
sub_ans.append(nums[i])
visited.append(i)
if self.dfs(nums, query, sub_ans, per_lst, visited):
# print(per_lst)
if not per_lst:
return nums[::-1]
return per_lst[-1]
sub_ans.pop()
visited.pop()
def previous_permuation(self, nums: List[int]) -> List[int]:
# write your code here
query = nums.copy()
nums = sorted(nums)
return self.dfs(nums, query, [], [], [])
边栏推荐
- 简单工厂和工厂方法模式
- 基于turtlebot3实现SLAM建图及自主导航仿真
- phpcms 提示信息頁面跳轉showmessage
- C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
- Deploying WordPress instance tutorial under coreos
- 《剑指offer 04》二维数组查找
- OpenGL 着色器使用
- 2022年中南大学夏令营面试经验
- vulnhub之Nagini
- Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
猜你喜欢
Slam mapping and autonomous navigation simulation based on turnlebot3
Vulnhub narak
Hongmeng fourth training
DS90UB949
"Jianzhi offer 04" two-dimensional array search
ftp登录时,报错“530 Login incorrect.Login failed”
vulnhub之raven2
Unity3D学习笔记5——创建子Mesh
Spl06-007 air pressure sensor (example of barometer)
ArcGIS application (XXI) ArcMap method of deleting layer specified features
随机推荐
R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
Mmc5603nj geomagnetic sensor (Compass example)
Raven2 of vulnhub
836. 合并集合(DAY 63)并查集
XML (DTD, XML parsing, XML modeling)
STL tutorial 10 container commonalities and usage scenarios
Dynamically monitor disk i/o with ZABBIX
Master and backup role election strategy in kept
ArcGIS application (XXI) ArcMap method of deleting layer specified features
Vulnhub geminiinc
rxjs Observable filter Operator 的实现原理介绍
MySQL searches and sorts out common methods according to time
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
一些常用术语
vulnhub之Ripper
Qt OpenGL 纹理贴图
利用Zabbix动态监控磁盘I/O
vulnhub之GeminiInc v2
Nestjs配置服务,配置Cookie和Session