当前位置:网站首页>LeetCode522-最长特殊序列II-哈希表-字符串-双指针
LeetCode522-最长特殊序列II-哈希表-字符串-双指针
2022-07-01 04:48:00 【李烦烦搞快点】
Note:
遍历列表,每次去判断当前的字符串是否不是其他字符串的子串,如果是,那就记录一下最长的答案,如果不是,那么就看其他的
代码如下:
class Solution {
public:
bool check(string s1, string s2){
int k = 0;
for(auto a: s2){
if(s1[k] == a)
k ++;
}
return k == s1.size();
}
int findLUSlength(vector<string>& strs) {
int res = -1;
for(int i = 0; i < strs.size(); i ++){
bool is_sub = false;
for(int j = 0; j < strs.size(); j ++){
if(i != j && check(strs[i], strs[j])){
is_sub = true;
break;
}
}
if(!is_sub)
res = max(res, (int)strs[i].size());
}
return res;
}
};
边栏推荐
- LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
- STM32 photoresistor sensor & two channel AD acquisition
- 【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
- 洗个冷水澡吧
- Pytorch neural network construction template
- VIM简易使用教程
- The index is invalid
- How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
- Use of dataloader
- Pytoch (I) -- basic grammar
猜你喜欢

C#读写应用程序配置文件App.exe.config,并在界面上显示

STM32扩展板 数码管显示

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点

STM32 extended key scan

PR 2021 quick start tutorial, learn about the and functions of the timeline panel

分布式事务-解决方案

分布式数据库数据一致性的原理、与技术实现方案

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target

数据加载及预处理

Pytorch(三) —— 函数优化
随机推荐
【FTP】FTP常用命令,持续更新中……
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
线程类的几大创建方法
Leecode question brushing record 1310 subarray XOR query
JS to solve the problem of floating point multiplication precision loss
This sideline workload is small, 10-15k, free unlimited massage
Query long transaction
Difficulties in the development of knowledge map & the importance of building industry knowledge map
先有网络模型的使用及修改
Shell之一键自动部署Redis任意版本
AssertionError assert I.ndim == 4 and I.shape[1] == 3
分布式-总结列表
分布式全局唯一ID解决方案详解
Codeforces Round #771 (Div. 2) ABCD|E
pytorch 卷积操作
Leecode record 1351 negative numbers in statistical ordered matrix
对象的序列化与反序列化
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
FileInputStream
Extension fragment
