当前位置:网站首页>leetcode:522. Longest special sequence II [greed + subsequence judgment]
leetcode:522. Longest special sequence II [greed + subsequence judgment]
2022-06-27 09:51:00 【Review of the white speed Dragon King】

analysis
Judge from the longest ( Ranking greed )
If the current str, Not the rest str The subsequence , Then it is the longest special sequence
Two pointer tracing method is used to determine the subsequence , See if the small sequence can be completed
ac code
class Solution:
def findLUSlength(self, strs: List[str]) -> int:
# a Is it b The subsequence
# Double pointer tracking ( classic )
def isSubSequnce(a, b):
n, m = len(a), len(b)
i = j = 0
while i < n and j < m:
if a[i] == b[j]:
i += 1
j += 1
return i == n
n = len(strs)
strs.sort(key = lambda x: -len(x))
#res = -1
for i in range(n):
flag = True
nstrs = strs[:i] + strs[i + 1:]
# The current cannot be a subsequence of any other string !
for ss in nstrs:
if isSubSequnce(strs[i], ss):
flag = False
break
if flag:
return len(strs[i])
return -1
summary
Subsequence judgment + Sort greedy biggest start
Topic understanding : The longest special sequence = The longest is not a sequence of other string subsequences
Small amount of data , Each of them can be judged ( From long to short is greed )
边栏推荐
- TDengine 邀请函:做用技术改变世界的超级英雄,成为 TD Hero
- R language uses econcharts package to create microeconomic or macro-economic charts, demand function to visualize demand curve, and customize the parameters of demand function to enrich the visualizat
- openpyxl表格读取实例
- 分布式文件存储系统的优点和缺点
- Quick start CherryPy (1)
- Easy to understand Laplace smoothing of naive Bayesian classification
- Unity - - newtonsoft. Analyse json
- js中的数组对象
- Advanced mathematics Chapter 7 differential equations
- 详解各种光学仪器成像原理
猜你喜欢

有關二叉樹的一些練習題

ucore lab4

ucore lab5

Your brain is learning automatically when you sleep! Here comes the first human experimental evidence: accelerate playback 1-4 times, and the effect of deep sleep stage is the best

Preliminary understanding of pytorch

1098 insertion or heap sort (PAT class a)

反编译jar包,修改后重新编译为jar包

Markem imaje马肯依玛士喷码机维修9450E打码机维修

ucore lab3

Tdengine invitation: be a superhero who uses technology to change the world and become TD hero
随机推荐
MySQL proficient-01 addition, deletion and modification
通俗易懂理解朴素贝叶斯分类的拉普拉斯平滑
prometheus告警流程及相关时间参数说明
Scientists develop two new methods to provide stronger security protection for intelligent devices
Markem imaje马肯依玛士喷码机维修9450E打码机维修
JS array splicing "suggested collection"
Five page Jump methods for wechat applet learning
CPU设计(单周期和流水线)
QT运行显示 This application failed to start because it could not find or load the Qt platform plugin
集合框架 泛型LinkedList TreeSet
文件名设置导致writelines写入报错:OSError: [Errno 22] Invalid argument
Semi-supervised Learning入门学习——Π-Model、Temporal Ensembling、Mean Teacher简介
Markem Imaje Marken IMAS printer maintenance 9450e printer maintenance
手机影像内卷几时休?
es 根据索引名称和索引字段更新值
强化学习中好奇心机制
多个类的设计
TDengine 邀请函:做用技术改变世界的超级英雄,成为 TD Hero
Curiosity mechanism in reinforcement learning
谷歌浏览器 chropath插件