当前位置:网站首页>Leetcode daily question - 522 Longest special sequence II
Leetcode daily question - 522 Longest special sequence II
2022-06-28 20:40:00 【Did HYK write the algorithm today】
List of articles
subject
Given string list strs , Return to it The longest special sequence . If the longest special sequence does not exist , return -1 .
Special sequence The definition is as follows : The sequence is a string Unique subsequence ( That is, it cannot be a subsequence of another string ).
s Of Subsequences can be made by deleting strings s Implementation of some characters in .
- for example ,“abc” yes “aebdc” The subsequence , Because you can delete "aebdc" Use the underscore character in to get “abc”
.“aebdc" The subsequence of also includes "aebdc”、 “aeb” and “” ( An empty string ).
Example
Example 1:
Input : strs = [“aba”,“cdc”,“eae”]
Output : 3
Example 2:
Input : strs = [“aaa”,“aaa”,“aa”]
Output : -1
Tips :
2 <= strs.length <= 50
1 <= strs[i].length <= 10
strs[i] Only lowercase letters
Ideas
- Meaning of this question : Find the length of the longest repeatless subsequence
- Here's a way of thinking : That is, the subsequence of a string is a non repeating subsequence , The string itself is also a non repeating subsequence ( perhaps : If this string is a subsequence of other strings , Then all subsequences of this string are subsequences of other strings , There is no need to compare subsequences of this string )
- According to this idea , Just judge whether this string is a subsequence of other strings , If this string is not a subsequence of all other strings , Record length , Finally, find the maximum length
Answer key
class Solution:
def findLUSlength(self, strs: List[str]) -> int:
# Determine whether it is a subsequence
def isson(str1, str2):
i,j = 0, 0
while i < len(str1) and j < len(str2):
if str1[i] == str2[j]:
i += 1
j += 1
else:
j += 1
return i == len(str1)
ans = -1
for i in range(len(strs)):
judge = True
for j in range(len(strs)):
if i == j:
continue
if isson(strs[i], strs[j]):
judge = False
break
# Maximum value of update results
if judge:
ans = max(ans, len(strs[i]))
return ans
边栏推荐
- Résumé de la stabilité
- [go language questions] go from 0 to entry 5: comprehensive review of map, conditional sentences and circular sentences
- 3. integrate listener
- LeetCode每日一题——30. 串联所有单词的子串
- On the complexity of software development and the way to improve its efficiency
- [learning notes] cluster analysis
- Win 10 create a gin framework project
- RT-Thread线程同步与线程通信
- Alibaba cloud MSE full link grayscale solution practice based on Apache apisik
- Jenkins pipeline's handling of job parameters
猜你喜欢

UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation

ThreadLocal principle

Figure neural network can also be used as CV backbone model. Huawei Noah Vig architecture is comparable to CNN and transformer

Rsync remote synchronization

RT thread thread synchronization and thread communication

Leetcode 36. 有效的数独(可以,一次过)

Jenkins pipeline's handling of job parameters
oracle delete误删除表数据后如何恢复

方 差 分 析

The principle and source code analysis of Lucene index construction
随机推荐
数据资产为王,如何解析企业数字化转型与数据资产管理的关系?
[learning notes] cluster analysis
Explanation of memory dump triggered by software watchdog and anr
Alibaba cloud MSE full link grayscale solution practice based on Apache apisik
怎么理解云原生数据库的易用性?
[go language questions] go from 0 to entry 5: comprehensive review of map, conditional sentences and circular sentences
ComparisonChain-文件名排序
The blocks problem (uva101) Purple Book p110vector application
Lucene构建索引的原理及源代码分析
Application of Andy s first dictionary (uva10815) Purple Book p112set
如何添加 logs来debug ANR 问题
The principle and source code analysis of Lucene index construction
【学习笔记】主成分分析法介绍
大智慧上怎么进行开户啊, 安全吗
Ehcache配置资料,方便自己查
Flask——总结
算力时代怎么「算」?「算网融合」先发优势很重要!
不同框架的绘制神经网络结构可视化
市值1200亿美金,老牌财税巨头Intuit是如何做到的?
T检验(检验两个总体的均值差异是否显著)