当前位置:网站首页>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 )
边栏推荐
- 使用aspose-slides将ppt转pdf
- Quartz(定时器)
- 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
- 邮件系统(基于SMTP协议和POP3协议-C语言实现)
- Tdengine invitation: be a superhero who uses technology to change the world and become TD hero
- Unity - - newtonsoft. Analyse json
- R语言plotly可视化:plotly可视化基础小提琴图(basic violin plot in R with plotly)
- leetcode:968. 监控二叉树【树状dp,维护每个节点子树的三个状态,非常难想权当学习,类比打家劫舍3】
- Bluetooth health management device based on stm32
- ucore lab3
猜你喜欢

Advanced mathematics Chapter 7 differential equations

Understand neural network structure and optimization methods

隐私计算FATE-离线预测

了解神经网络结构和优化方法

E+h secondary meter repair pH transmitter secondary display repair cpm253-mr0005

SVN版本控制器的安装及使用方法

Bluetooth health management device based on stm32

On anchors in object detection

TDengine 邀请函:做用技术改变世界的超级英雄,成为 TD Hero

最全H桥电机驱动模块L298N原理及应用
随机推荐
Shortcut key bug, reproducible (it seems that bug is the required function [funny.Gif])
TDengine 邀请函:做用技术改变世界的超级英雄,成为 TD Hero
[system design] proximity service
Pakistani security forces killed 7 terrorists in anti-terrorism operation
R language plot visualization: visualize the normalized histograms of multiple data sets, add density curve KDE to the histograms, set different histograms to use different bin sizes, and add edge whi
On June 23, the video address of station B in the third episode of rust chat room
借助原子变量,使用CAS完成并发操作
When does the mobile phone video roll off?
torchvision.models._utils.IntermediateLayerGetter使用教程
队列,双向队列,及其运用
快速入门CherryPy(1)
Parameters argc and argv of main()
[STM32] Hal library stm32cubemx tutorial 12 - IIC (read AT24C02)
R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行center中心化(每个数据列减去平均值)、设置method参数为center
JS array splicing "suggested collection"
10 常见网站安全攻击手段及防御方法
How do I get the STW (pause) time of a GC (garbage collector)?
Use aspese Cells convert Excel to PDF
使用Aspose.cells将Excel转成PDF
隐私计算FATE-离线预测