当前位置:网站首页>Li Kou today's question -522 Longest special sequence
Li Kou today's question -522 Longest special sequence
2022-06-28 15:03:00 【Struggling young man】
522. The longest special sequence II
Ideas : Subsequence , It's not a string , So there is no need to pay attention to whether it is continuous .s The special sequence of can he delete the string s Implementation of some characters in .
Topic translation : Give an array of strings , Find the string inside to satisfy The current string is not a subsequence of other strings in the string array
, Returns the string that meets the condition The length of the longest string
Use a double loop , The outer layer enumerates each string str[i] As a special sequence , The inner layer enumerates each string str[j] (i != j)
, Judge str[i] If not for str[j] Subsequence of .
Judge str[i] Whether it is str[j] The subsequence , You can use the double pointer method . Initial pointer pi and pj Points to the first character of two strings , If two characters are the same , Then both pointers move one position to the right , Indicates that the match is successful , Otherwise, just move to the right pj, Indicates that the match failed . If pi After traversing the entire string , Just explain str[i] yes str [j] The subsequence .
In all satisfied str[i] in , Choose the longest one , Return the length as the answer , If it doesn't exist, return -1
class Solution {
public int findLUSlength(String[] strs) {
int n = strs.length;
int ans = -1;
for (int i = 0; i < n; ++i) {
// Set a flag
boolean check = true;
for (int j = 0; j < n; ++j) {
// As long as it is found in other strings that it is a subsequence , Then mark it as false, Exit loop
if (i != j && is_son(strs[i], strs[j])) {
check = false;
break;
}
}
// In all the “ orphan ” Find the longest one in , Assign a value to ans.
if (check) {
ans = Math.max(ans, strs[i].length());
}
}
return ans;
}
public boolean is_son(String s, String t) {
// Define two pointers
int ptS = 0, ptT = 0;
while (ptS < s.length() && ptT < t.length()) {
if (s.charAt(ptS) == t.charAt(ptT)) {
++ptS;
}
++ptT;
}
// Back to Shanghai true perhaps false If you wait , Then return to true
return ptS == s.length();
}
}
Actually, reading comprehension questions , It will not be so difficult .
边栏推荐
- After nearly 20 years of operation, the Mars probe software based on win 98 has been upgraded for the first time
- Recommended practice sharing of Zhilian recruitment based on Nebula graph
- 请问一下,是不是insert all这种oracle的批量新增没拦截?
- 2022年最新PyCharm激活破解码永久_详细安装教程(适用多版本)
- 使用LamdbaUpdateWrapper的setSql作用及风险
- 成龙和快品牌,谁才是快手的救星?
- 最长连续序列
- 论文解读(GCC)《Efficient Graph Convolution for Joint Node RepresentationLearning and Clustering》
- The boss told me three times: low key, low key, low key
- R语言ggplot2可视化:patchwork包将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图、两个可视化的组合结果对齐、并为组合图像的每个子图添加标题
猜你喜欢
Introduction to common components of IOT low code platform
成龙和快品牌,谁才是快手的救星?
Softing epgate Pb series Gateway - integrates the Profibus bus into the ethernet/ip network
完整的模型训练套路(一)
WPF 视频硬解码渲染播放(无空域)(支持4K、8K、高帧率视频)
老板嘱咐了三遍:低调、低调、低调
Ding! Techo day Tencent technology open day arrived as scheduled!
Jingyuan's safe sprint to the Growth Enterprise Market: it plans to raise 400million yuan for investment and Yunyou software is the shareholder
Maingene listed on the Hong Kong Stock Exchange: IPO with a market value of HK $4.3 billion was ignored by the market
使用Karmada实现Helm应用的跨集群部署
随机推荐
不要使用短路逻辑编写 stl sorter 多条件比较
Youju new material rushes to Shenzhen Stock Exchange: it plans to raise 650million yuan, with an annual revenue of 333million yuan
Jingyuan's safe sprint to the Growth Enterprise Market: it plans to raise 400million yuan for investment and Yunyou software is the shareholder
环保产品“绿色溢价”高?低碳生活方式离人们还有多远
10 key points to effectively improve performance interview
技术弄潮儿
Vscode writes markdown file and generates pdf
抽奖动画 - 鲤鱼跳龙门
Differences between ram ROM flash
Leetcode(406)——根据身高重建队列
Softing epgate Pb series Gateway - integrates the Profibus bus into the ethernet/ip network
324. swinging sort II: not a simple construction problem
Angers medical sprint scientific innovation board: annual revenue of RMB 300million and proposed fund raising of RMB 770million
动力电池,是这样被“瓜分”的
Maingene listed on the Hong Kong Stock Exchange: IPO with a market value of HK $4.3 billion was ignored by the market
How to solve the following problems in the Seata database?
笔试面试算法经典–最长回文子串
[C language] how to implement plural types
Steve Jobs of the United States, died; China jobs, sold
组合总和-Leetcode