当前位置:网站首页>522. longest special sequence II (greedy & double pointer)
522. longest special sequence II (greedy & double pointer)
2022-06-28 19:55:00 【Harris-H】
522. The longest special sequence II( greedy & Double pointer )
There is a property to consider : If the subsequence of a string is a special sequence , So the string itself is also .
The question is simplified to judge whether a string is a subsequence of other strings . Obviously greedy + Double pointer .
Time complexity : 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;
}
};
边栏推荐
- QSP读取标签配置错误问题
- JVM memory structure
- Gaozelong, a digital economy expert: Yingke changed its name to yingcosmos. Will yuancosmos become the next growth engine of Yingke?
- head、tail查看文件
- 秒杀系统设计
- R语言GLM广义线性模型:逻辑回归、泊松回归拟合小鼠临床试验数据(剂量和反应)示例和自测题
- 微信小程序_8,视图与逻辑
- jsp中获取session中的值
- 2022年4月10日--使用C#迈出第一步--使用C#从.NET类库调用方法(没看懂)
- Markdown drawing Mermaid practical tutorial
猜你喜欢

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

2022茶艺师(中级)考试模拟100题及模拟考试

H5 sunflower operation

C#应用程序界面开发基础——窗体控制

Time series forecasting based on trend and seasonality

论文笔记:Universal Value Function Approximators

Demo of integrated development of intelligent computing system 3 plugin

Intelligent computing system 1 environment construction

Ffmpeg usage in video compression processing

集合之ArrayList
随机推荐
NanoPC-T4(RK3399) game1 oled(I2C)显示时间天气温度
Class loading mechanism and object creation
2022焊工(初级)特种作业证考试题库及答案
Leetcode week 299
管道 | 与重定向 >
Digital collection, ten thousand words long text, most of the questions you want to know have been clearly explained, which must be seen by practitioners
蓝桥杯 历届试题 蚂蚁感冒
首部元宇宙概念小说《元宇宙2086》获得2022年上袭元宇宙奖
Server configuration estimation of core IOT Bluetooth AOA positioning system
ROS中quaternion四元數和歐拉角轉換
判断字符串是否为空
R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
C # application interface development foundation - form control
Configuration du mode tcwind
Past blue bridge cup test questions ants catch cold
Constrained Delaunay triangulation in MATLAB
2280.Cupboards
图神经网络入门 (GNN, GCN)
2022年T电梯修理考试题库模拟考试平台操作
Database learning notes (sql04)