当前位置:网站首页>522. 最长特殊序列 II(贪心&双指针)
522. 最长特殊序列 II(贪心&双指针)
2022-06-28 19:39:00 【Harris-H】
522. 最长特殊序列 II(贪心&双指针)
需要考虑一个性质:如果一个串的子序列是特殊序列,那么这个串本身也是。
题目就简化成判断字符串是否为其他串的子序列。显然可以贪心+双指针。
时间复杂度: O ( n 2 l ) O(n^2l) O(n2l)
class Solution {
public:
int findLUSlength(vector<string>& a) {
int n = a.size();
int ans = -1;
for(int k=0;k<n;k++){
string s = a[k];
int ok = 1;
for(int i=0;i<n;i++){
string t = a[i];
if(i==k||t.size()<s.size()) continue;
int pi=0,pj=0;
int m = (int)s.size();
int l = t.size();
while(pi<m&&pj<l){
if(s[pi]==t[pj]) pi++,pj++;
else pj++;
}
if(pi==m){
ok = 0;
break;
}
}
if(ok) ans=max(ans,(int)s.size());
}
return ans;
}
};
边栏推荐
- The first meta universe concept novel, meta universe 2086, won the upper attack meta universe award in 2022
- Can py SQL get the table structure?
- 100人成绩的平均
- Parallax JS special effect JS carousel map plug-in
- Markdown绘图mermaid实用教程
- Huawei cloud onemeeting tells you that the whole scene meeting is held like this!
- PCL calculation of center and radius of circumscribed circle of plane triangle
- From design delivery to development, it is easy and efficient!
- jsp中获取session中的值
- redisTemplate
猜你喜欢

Variational graph auto-encoders (VGAE)

Variational graph auto-encoders (VGAE)

The amazing nanopc-t4 (rk3399) is used as the initial configuration and related applications of the workstation

Severity code description project file line suppress status error lnk2038 detected a mismatch of "runtimelibrary": the value "md\u dynamicrelease" does not match the value "mdd\u dynamicde"

腾讯汤道生:面向数实融合新世界,开发者是最重要的“建筑师”

论文3 VScode&texlive&SumatraPDF打造完美书写论文工具

Nanopc-t4 (rk3399) Game1 OLED (I2C) display time weather temperature

Leetcode week 299

How to resolve kernel errors? Solution to kernel error of win11 system

变分自编码器 (Variational Autoencoders, VAEs)
随机推荐
Industry analysis - quick intercom, building intercom
Markdown mermaid种草(1)_ mermaid简介
为什么C语言用使用其他文件的结构体变量时,声明结构体别名还不行,必须使用本名?(使用别名时不能加struct)
C # application interface development foundation - form control
阿里开源(EasyExcel)
Facts / assertions / assertions / conclusions / assertions / judgments
Wechat applet_ 8. View and logic
【Go语言刷题篇】Go从0到入门5:Map综合复习、条件语句、循环语句练习
使用点云构建不规则三角网TIN
Judge whether the string is empty
Ali open source (easyexcel)
Building tin with point cloud
腾讯汤道生:面向数实融合新世界,开发者是最重要的“建筑师”
1002_ twenty million one hundred and eighty-one thousand and nineteen
还在付费下论文吗?快来跟我一起白piao知网
Variational graph auto-encoders (VGAE)
Web3 that unleashes the value of the Internet
matlab 受约束的 Delaunay 三角剖分
智能计算系统2 bangc算子开发的demo (CPU和MLU270的异构编程流程)
I just bought the ADB MySQL service. Every time I do an operation, such as creating a table, this problem will pop up. What is the problem?