当前位置:网站首页>previous permutation lintcode51
previous permutation lintcode51
2022-07-03 10:59:00 【换个名字就很好】
TLE版本
这个版本无法通过。只是为了自己加深dfs的理解。
时间复杂度O(N^N), 对于每一个位置,都要遍历n次, 有n个位置。
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, [], [], [])
边栏推荐
- 剑指offer专项32-96题做题笔记
- R language uses grid of gridextra package The array function combines multiple visual images of the ggplot2 package horizontally, and the ncol parameter defines the number of columns of the combined g
- FL Studio 20无限试用版水果编曲下载
- Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
- Programmers' entrepreneurial trap: taking private jobs
- Modular programming of single chip microcomputer
- P3250 [hnoi2016] Network + [necpc2022] f.tree path tree section + segment tree maintenance heap
- The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
- Qt+VTK+OCCT读取IGES/STEP模型
- Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests
猜你喜欢

Kubernetes 三打探针及探针方式

Numpy np.max和np.maximum实现relu函数

Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution

聊聊Flink框架中的状态管理机制

STL教程9-容器元素深拷贝和浅拷贝问题

AOSP ~ NTP ( 网络时间协议 )

MATLAB提取不规则txt文件中的数值数据(简单且实用)

836. 合并集合(DAY 63)并查集

Intel 13th generation core flagship exposure, single core 5.5ghz

MATLAB提取不規則txt文件中的數值數據(簡單且實用)
随机推荐
C language AES encryption and decryption
[vtk] interpretation of source code comments of vtkwindowedsincpolydatafilter
How to mix embedded MCU, arm and DSP?
uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
JGG专刊征稿:时空组学
银泰百货点燃城市“夜经济”
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
Technical experts from large factories: how can engineers improve their communication skills?
Illustrated network: what is virtual router redundancy protocol VRRP?
MATLAB提取不規則txt文件中的數值數據(簡單且實用)
mysql使用update联表更新的方法
00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
. \vmware-vdiskmanager. exe -k “c:\\xxxxx.vmdk”
ASP. Net hotel management system
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
Execute kubectl on Tencent cloud container service node
Hongmeng third training (project training)
Double linked list of linear list