题目如下:

解题思路:因为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的更多相关文章

  1. 【LeetCode】522. Longest Uncommon Subsequence II 解题报告(Python)

    [LeetCode]522. Longest Uncommon Subsequence II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemin ...

  2. 【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. 【leetcode】521. Longest Uncommon Subsequence I

    problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...

  4. 522. Longest Uncommon Subsequence II

    Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...

  5. 【leetcode】300.Longest Increasing Subsequence

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  6. 【LeetCode】516. Longest Palindromic Subsequence 最长回文子序列

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题思路 代码 刷题心得 日期 题目地址:https://le ...

  7. 【LeetCode】594. Longest Harmonious Subsequence 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计次数 日期 题目地址:https://leetc ...

  8. 【LeetCode】300. Longest Increasing Subsequence 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  9. 【leetcode】1218. Longest Arithmetic Subsequence of Given Difference

    题目如下: Given an integer array arr and an integer difference, return the length of the longest subsequ ...

随机推荐

  1. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_7 Mybatis中使用代理Dao的执行过程分析

    另外一种情况,不写Mybits的dao实现类的情况. 切换工程到CRUD的工程.这里面是不写dao实现类的方式 进入到GetMaper里面.这里是创建代理对象 去找SqlSession的实现类Defa ...

  2. HTML5——添加新元素 新元素 Canvas SVG MathML 黑客帝国特效

    为HTML添加新元素 添加新元素   +   该元素定义样式 <!DOCTYPE html> <html> <head> <meta charset=&quo ...

  3. hdu5993/2016icpc青岛L

    zz:https://www.cnblogs.com/ytytzzz/p/9674661.html 题意:给一棵树,每次询问删掉两条边,问剩下的三棵树的最大直径点10W,询问10W,询问相互独立 So ...

  4. [19/06/05-星期三] CSS基础_样式表的位置(内联、内部、外部样式)、块元素(div)、内联元素(span)、常用的选择器

    一.概念 CSS(Cascading Style Sheets,层叠样式表) 可以用来为网页创建样式表,通过样式表可以对网页进行装饰. 所谓层叠,就是可以将整个网页想象成是一层一层的结构,层次高的将会 ...

  5. Java中字符编码和字符串所占字节数 .

    首 先,java中的一个char是2个字节.java采用unicode,2个字节来表示一个字符,这点与C语言中不同,C语言中采用ASCII,在大多数 系统中,一个char通常占1个字节,但是在0~12 ...

  6. C语言黑与白问题

    问题描述: 有A.B.C.D.E这5个人,每个人额头上都帖了一张黑或白的纸.5人对坐,每 个人都可以看到其他人额头上纸的颜色.5人相互观察后: A说:“我看见有3人额头上贴的是白纸,1人额头上贴的是黑 ...

  7. The order of a Tree

    The order of a Tree Problem Description As we know,the shape of a binary search tree is greatly rela ...

  8. Centos7Yum安装PHP7.2流程

    Centos7Yum安装PHP7.21.安装源 安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包. php高版本的yum源地址,有两部分,其中一部分是epel-relea ...

  9. [LeetCode] 135. 分发糖果

    题目链接 : https://leetcode-cn.com/problems/candy/ 题目描述: 老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分 ...

  10. linux:输入/输出、重定向、管道

    输入.输出: 程序的默认输入设备,叫标准输入. stdin    键盘   0 程序的默认输出设备,叫标准输出. stdout    监视器    1 程序的默认错误输出设备,叫标准错误输出.stde ...