当前位置:网站首页>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 )
边栏推荐
- 测试同学怎么参与codereview
- CPU设计(单周期和流水线)
- 【系统设计】邻近服务
- R语言使用econocharts包创建微观经济或宏观经济图、demand函数可视化需求曲线(demand curve)、自定义配置demand函数的参数丰富可视化效果
- 使用Aspose.cells将Excel转成PDF
- Use CAS to complete concurrent operations with atomic variables
- 了解神经网络结构和优化方法
- ucore lab5
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- Take you to play with the camera module
猜你喜欢

最全H桥电机驱动模块L298N原理及应用

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

Privacy computing fat offline prediction

Es update values based on Index Names and index fields

.NET 中的引用程序集

通俗易懂理解樸素貝葉斯分類的拉普拉斯平滑

【生动理解】深度学习中常用的各项评价指标含义TP、FP、TN、FN、IoU、Accuracy

ucore lab4

ucore lab4

【报名】基础架构设计:从架构热点问题到行业变迁 | TF63
随机推荐
前馈-反馈控制系统设计(过程控制课程设计matlab/simulink)
谷歌浏览器 chropath插件
Quick start CherryPy (1)
Take you to play with the camera module
Apache POI的读写
多個類的設計
Preliminary understanding of pytorch
torchvision.models._utils.IntermediateLayerGetter使用教程
文件名设置导致writelines写入报错:OSError: [Errno 22] Invalid argument
Advanced mathematics Chapter 7 differential equations
es 根据索引名称和索引字段更新值
prometheus告警流程及相关时间参数说明
TDengine 邀请函:做用技术改变世界的超级英雄,成为 TD Hero
MYSQL精通-01 增删改
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
Installation and use of SVN version controller
ucore lab3
Shortcut key bug, reproducible (it seems that bug is the required function [funny.Gif])
SVN版本控制器的安装及使用方法
视频文件太大?使用FFmpeg来无损压缩它