【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 ...
随机推荐
- 阶段3 1.Mybatis_11.Mybatis的缓存_8 mybatis的二级缓存
二级缓存: 它指的是Mybatis中SqlSessionFactory对象的缓存.由同一个SqlSessionFactory对象创建的SqlSession共享其缓存. ...
- Jmeter接口测试系列之判断测试结果
在使用jmeter进行接口测试时,我们需要根据测试用例判断其测试结果是否一致,判断其执行是否成功. 在jmeter中也可以使用响应断言去判断,但是有时我们需要根据不同的用例,其判断条件不同,所以这里我 ...
- 自定义标记mark
前言 pytest可以支持自定义标记,自定义标记可以把一个web项目划分多个模块,然后指定模块名称执行.app自动化的时候,如果想android和ios公用一套代码时,也可以使用标记功能,标明哪些是i ...
- Linx下Keepalived做成服务
在/usr目录下面执行: find -name keepalived 返回如下: ./sbin/keepalived ./local/sbin/keepalived ./local/etc/keepa ...
- pg和mysql对比
作者:方圆链接:https://www.zhihu.com/question/20010554/answer/15863274来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
- python每日一练:0007题
第 0007 题: 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但是要分别列出来. # -*- coding:utf-8 -*- import os def count ...
- 一个简单的dns服务器
options { listen-on port 53 { any; }; listen-on-v6 port 53 { any; }; directory "/srv/app/named& ...
- python 并发编程 多进程 互斥锁
运行多进程 每个子进程的内存空间是互相隔离的 进程之间数据不能共享的 一 互斥锁 但是进程之间都是运行在一个操作系统上,进程之间数据不共享,但是共享同一套文件系统,所以访问同一个文件,或同一个打印终 ...
- [转帖]mysql.sock的作用
mysql.sock的作用 链接:http://blog.itpub.net/28602568/viewspace-1797619/ 标题:mysql.sock的作用 作者:lōττéry©版权所有[ ...
- [19/10/16-星期四] Python中的文件操作
一.打开文件 # open(file, mode='r', buffering=-1, encoding_=None, errors=None, newline=None, closefd=True, ...