【leetcode】522. Longest Uncommon Subsequence II
题目如下:

解题思路:因为given list长度最多是50,我的解法就比较随意了,直接用一个嵌套的循环,判断数组中每个元素是否是其他的subsequence,最后找出不属于任何元素subsequence的最长元素即可。
代码如下:
class Solution(object):
def isSubsequence(self, a, b):
"""
:type a: str
:type b: str
:rtype: int
"""
s = b
for i in a:
inx = s.find(i)
if inx == -1:
return False
s = s[inx+1:]
return True def findLUSlength(self, strs):
"""
:type strs: List[str]
:rtype: int
"""
def cmpf(v1,v2):
return len(v2) - len(v1)
strs.sort(cmp = cmpf)
if len(strs) == 0 or len(strs[0]) == 0:
return -1
res = -1 visit = [0 for x in strs]
for i in range(len(strs)):
if visit[i] == 1:
continue
tmp = False
for j in range(len((strs))):
if i == j:
continue
tmp = self.isSubsequence(strs[i],strs[j])
if tmp == True:
visit[i] = 1 for i in xrange(len(visit)):
if visit[i] == 0:
return len(strs[i])
return -1
【leetcode】522. Longest Uncommon Subsequence II的更多相关文章
- 【LeetCode】522. Longest Uncommon Subsequence II 解题报告(Python)
[LeetCode]522. Longest Uncommon Subsequence II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemin ...
- 【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】521. Longest Uncommon Subsequence I
problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...
- 522. Longest Uncommon Subsequence II
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...
- 【leetcode】300.Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 【LeetCode】516. Longest Palindromic Subsequence 最长回文子序列
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题思路 代码 刷题心得 日期 题目地址:https://le ...
- 【LeetCode】594. Longest Harmonious Subsequence 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计次数 日期 题目地址:https://leetc ...
- 【LeetCode】300. Longest Increasing Subsequence 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】1218. Longest Arithmetic Subsequence of Given Difference
题目如下: Given an integer array arr and an integer difference, return the length of the longest subsequ ...
随机推荐
- HAProxy、Keepalived 在 Ocatvia 的应用实现与分析
目录 文章目录 目录 Amphora 启动 keepalived 启动 haproxy 最后 Amphora 创建一个 loadbalancer 需要占用一到两台 Amphora Instance 作 ...
- nginx排查502错误
排查502错误1.查看/usr/local/nginx/conf/nginx.conf从而知道其错误日志在哪.重点查看其错误日志.2.如果是/tmp/dd.sock2017/05/01 18:48:3 ...
- Vue中的model
v-model语法糖: model: 默认情况下,一个组件上的 v-model 会把 value 用作 prop 且把 input 用作 event, 但是一些输入类型比如单选框和复选框按钮可能想使用 ...
- Django 实现分库
网站后端的数据库随着业务的不断扩大,用户的累积,数据库的压力会逐渐增大.一种办法是优化使用方法,也就是的优化 SQL 语句啦,添加缓存以达到减少存取的目的:另外一种办法是修改使用架构,在数据库层面上「 ...
- Canvas入门05-渐变颜色
线性渐变API: ctx.createLinearGradient(double x1, double y1, double x2, double y2) 创建一个渐变实例 (x1, y1) 渐变的起 ...
- linux文件属性软硬连接
硬链接:ln 源文件 目标文件 软链接:ln -s 源文件 目标文件 硬链接总结: 1.具有相同inode节点号的多个文件互为硬链接文件 2.删除硬链接文件或者删除源文件任意之一,文件实体并未被删除. ...
- [转帖]是时候深入了解Linux的系统结构
是时候深入了解Linux的系统结构 http://os.51cto.com/art/201905/596011.htm linux的体系结果 其实自己也知道 linus 做了一个 kernel 大 ...
- Bootstrap字体图标Font-Awesome 使用教程
转载自:https://blog.csdn.net/crper/article/details/46293295 以备记录使用.
- [LeetCode] 92. 反转链表 II
题目链接 : https://leetcode-cn.com/problems/reverse-linked-list-ii/ 题目描述: 反转从位置 m 到 n 的链表.请使用一趟扫描完成反转. 说 ...
- Desert King(01分数规划问题)(最优斜率生成树)
Desert King Time Limit: 3000MS Memory Limit: 65536K Total Submissions:33847 Accepted: 9208 Descr ...